From 4447d3c0383c336582035a7fe1d322ba0e8aef5f Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 07:49:58 +0000 Subject: [PATCH 1/2] Keep the dev server from reporting to Sentry The Cypress runs in CI use the dev server, and each run sent 92 to 172 errors to Sentry, tagged as production. Since the PR builds picked up in November, they used up most of the reserved error volume. --- src/app.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/app.tsx b/src/app.tsx index 4f3e2e8e..c47d500c 100755 --- a/src/app.tsx +++ b/src/app.tsx @@ -41,6 +41,9 @@ import { redactBreadcrumb, redactEvent } from './util/sentryRedaction'; Sentry.init({ dsn: "https://8a606d82aa68850021fbfac2ffda30b5@o4509293310967808.ingest.de.sentry.io/4509293314113617", + // The dev server (`npm start`, also used by the Cypress runs in CI) + // must not report: its errors would eat the reserved Sentry volume + enabled: !__DEV__, // Our DPA rules out personal data in Sentry. Sentry v11 collects user // info (incl. IP address), cookies, headers and bodies by default, so // switch every data collection category off explicitly. From f1970da5027d5935b270999fbf3249dd6fc4f91d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 07:49:58 +0000 Subject: [PATCH 2/2] Do not report admin settings listeners cancelled by sign-out When an admin signs out, Firebase cancels the listeners on the admin-only settings with permission_denied, often before the sign-out reaches the sagas that would remove them. Each such sign-out sent four errors to Sentry. A denial while someone is still signed in, and any other cancel, is still reported. --- .../settings/watchSettingWhileAdmin.spec.ts | 30 +++++++++++++++++-- .../settings/watchSettingWhileAdmin.ts | 13 ++++++-- src/util/firebase.spec.ts | 12 ++++++++ src/util/firebase.ts | 5 ++++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/modules/settings/watchSettingWhileAdmin.spec.ts b/src/modules/settings/watchSettingWhileAdmin.spec.ts index fa5da7ca..74615e0d 100644 --- a/src/modules/settings/watchSettingWhileAdmin.spec.ts +++ b/src/modules/settings/watchSettingWhileAdmin.spec.ts @@ -1,6 +1,6 @@ import {runSaga, stdChannel} from 'redux-saga'; import {onValue} from 'firebase/database'; -import firebase from '../../util/firebase'; +import firebase, {isSignedIn} from '../../util/firebase'; import {error} from '../../util/log'; import {FIREBASE_AUTHENTICATION_EVENT} from '../auth/actions'; import {watchSettingWhileAdmin} from './watchSettingWhileAdmin'; @@ -23,6 +23,11 @@ const authEvent = (authData: any) => ({ const adminLogin = () => authEvent({uid: 'admin-uid', admin: true}); const userLogin = () => authEvent({uid: 'user-uid', admin: false}); const logout = () => authEvent(null); +// Shaped like the errors Firebase passes to a cancelled listener +const permissionDenied = () => Object.assign( + new Error(`permission_denied at ${PATH}: Client doesn't have permission to access the desired data.`), + {code: 'PERMISSION_DENIED'} +); describe('modules', () => { describe('settings', () => { @@ -42,6 +47,7 @@ describe('modules', () => { beforeEach(() => { jest.clearAllMocks(); (firebase as jest.Mock).mockImplementation((path: string) => ({path})); + (isSignedIn as jest.Mock).mockReturnValue(true); unsubscribe = jest.fn(); (onValue as jest.Mock).mockReturnValue(unsubscribe); @@ -129,7 +135,7 @@ describe('modules', () => { it('logs and allows a new subscription when Firebase cancels the listener', () => { emit(adminLogin()); - const denied = new Error('permission_denied'); + const denied = permissionDenied(); lastListener().onCancel(denied); expect(error).toHaveBeenCalledWith(`Listener for ${PATH} was cancelled`, denied); @@ -137,6 +143,26 @@ describe('modules', () => { emit(adminLogin()); expect(onValue).toHaveBeenCalledTimes(2); }); + + it('does not log a permission_denied cancel after the sign-out', () => { + emit(adminLogin()); + (isSignedIn as jest.Mock).mockReturnValue(false); + lastListener().onCancel(permissionDenied()); + + expect(error).not.toHaveBeenCalled(); + + emit(adminLogin()); + expect(onValue).toHaveBeenCalledTimes(2); + }); + + it('logs other cancels after the sign-out', () => { + emit(adminLogin()); + (isSignedIn as jest.Mock).mockReturnValue(false); + const unavailable = Object.assign(new Error('unavailable'), {code: 'UNAVAILABLE'}); + lastListener().onCancel(unavailable); + + expect(error).toHaveBeenCalledWith(`Listener for ${PATH} was cancelled`, unavailable); + }); }); }); }); diff --git a/src/modules/settings/watchSettingWhileAdmin.ts b/src/modules/settings/watchSettingWhileAdmin.ts index feae9f75..dd398f70 100644 --- a/src/modules/settings/watchSettingWhileAdmin.ts +++ b/src/modules/settings/watchSettingWhileAdmin.ts @@ -2,11 +2,18 @@ import {END, eventChannel, Task} from 'redux-saga'; import {cancel, fork, put, take, takeEvery} from 'redux-saga/effects'; import {onValue} from 'firebase/database'; import {FIREBASE_AUTHENTICATION_EVENT} from '../auth/actions'; -import firebase from '../../util/firebase'; +import firebase, {isSignedIn} from '../../util/firebase'; import {error} from '../../util/log'; type LoadedActionCreator = (value: any) => { type: string }; +// Signing out makes Firebase cancel the admin-only listeners with +// permission_denied, often before the sign-out reaches the sagas that +// would remove them. Such a cancel is expected and not worth reporting. +function isDeniedAfterSignOut(e: unknown) { + return (e as any)?.code === 'PERMISSION_DENIED' && !isSignedIn(); +} + // Emits `loaded(value)` for every change at `path`. Closing the channel // removes the Firebase listener. If Firebase cancels the listener (e.g. // permission denied), the error is logged and the channel ends. @@ -15,7 +22,9 @@ export function createSettingChannel(path: string, loaded: LoadedActionCreator) firebase(path), snapshot => emit(loaded(snapshot.val())), e => { - error(`Listener for ${path} was cancelled`, e); + if (!isDeniedAfterSignOut(e)) { + error(`Listener for ${path} was cancelled`, e); + } emit(END); } )); diff --git a/src/util/firebase.spec.ts b/src/util/firebase.spec.ts index f6fce084..e86caca5 100644 --- a/src/util/firebase.spec.ts +++ b/src/util/firebase.spec.ts @@ -45,6 +45,7 @@ import firebaseDefault, { unauth, loadValue, getIdToken, + isSignedIn, } from './firebase'; describe('util/firebase', () => { @@ -307,4 +308,15 @@ describe('util/firebase', () => { expect(result).toBe(mockToken); }); }); + + describe('isSignedIn', () => { + it('returns true when a user is signed in', () => { + expect(isSignedIn()).toBe(true); + }); + + it('returns false when nobody is signed in', () => { + mockAuth.currentUser = null; + expect(isSignedIn()).toBe(false); + }); + }); }); diff --git a/src/util/firebase.ts b/src/util/firebase.ts index e8d5a8df..f65225fb 100644 --- a/src/util/firebase.ts +++ b/src/util/firebase.ts @@ -114,6 +114,11 @@ export function getIdToken() { return getAuth().currentUser!.getIdToken(); } +export function isSignedIn() { + initialize(); + return !!getAuth().currentUser; +} + export default firebase; if ((window as any).Cypress) {