Skip to content

Commit 14e5e48

Browse files
authored
ref(replay): Enable no-console rule (#6347)
1 parent cbf8e4d commit 14e5e48

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

packages/replay/.eslintrc.js

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ module.exports = {
3737
{
3838
files: ['*.ts', '*.tsx', '*.d.ts'],
3939
rules: {
40-
// TODO (high-prio): Go through console logs and figure out which ones should be replaced with the SDK logger
41-
'no-console': 'off',
4240
// TODO (high-prio): Re-enable this after migration
4341
'@typescript-eslint/explicit-member-accessibility': 'off',
4442
// TODO (high-prio): Remove this exception from naming convention after migration

packages/replay/src/eventBuffer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class EventBufferCompressionWorker implements IEventBuffer {
130130
try {
131131
stringifiedArgs = JSON.stringify(args);
132132
} catch (err) {
133-
console.error(err);
133+
__DEBUG_BUILD__ && logger.error('[Replay] Error when trying to stringify args', err);
134134
stringifiedArgs = '[]';
135135
}
136136

packages/replay/src/index.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ export class Replay implements Integration {
181181

182182
// TODO(deprecated): Maintain backwards compatibility for alpha users
183183
if (usingDeprecatedCaptureOnlyOnError) {
184+
// eslint-disable-next-line no-console
184185
console.warn(
185186
'[@sentry/replay]: The `captureOnlyOnError` option is deprecated! Please configure `errorSampleRate` instead.',
186187
);
187188
}
188189

189190
if (usingDeprecatedReplaysSamplingRate) {
191+
// eslint-disable-next-line no-console
190192
console.warn(
191193
'[@sentry/replay]: The `replaysSamplingRate` option is deprecated! Please configure `sessionSampleRate` instead.',
192194
);
@@ -1084,7 +1086,7 @@ export class Replay implements Integration {
10841086
*/
10851087
async runFlush(): Promise<void> {
10861088
if (!this.session) {
1087-
console.error(new Error('[Sentry]: No transaction, no replay'));
1089+
__DEBUG_BUILD__ && logger.error('[Replay] No session found to flush.');
10881090
return;
10891091
}
10901092

@@ -1117,8 +1119,8 @@ export class Replay implements Integration {
11171119
eventContext,
11181120
});
11191121
} catch (err) {
1122+
__DEBUG_BUILD__ && logger.error(err);
11201123
captureInternalException(err);
1121-
console.error(err);
11221124
}
11231125
}
11241126

@@ -1139,7 +1141,7 @@ export class Replay implements Integration {
11391141
}
11401142

11411143
if (!this.session?.id) {
1142-
console.error('[Replay]: No transaction, no replay');
1144+
__DEBUG_BUILD__ && logger.error('[Replay] No session found to flush.');
11431145
return;
11441146
}
11451147

@@ -1165,7 +1167,7 @@ export class Replay implements Integration {
11651167
try {
11661168
await this.flushLock;
11671169
} catch (err) {
1168-
console.error(err);
1170+
__DEBUG_BUILD__ && logger.error(err);
11691171
} finally {
11701172
this.debouncedFlush();
11711173
}
@@ -1310,13 +1312,13 @@ export class Replay implements Integration {
13101312
});
13111313
this.resetRetries();
13121314
return true;
1313-
} catch (ex) {
1314-
console.error(ex);
1315+
} catch (err) {
1316+
__DEBUG_BUILD__ && logger.error(err);
13151317
// Capture error for every failed replay
13161318
setContext('Replays', {
13171319
retryCount: this.retryCount,
13181320
});
1319-
captureInternalException(ex);
1321+
captureInternalException(err);
13201322

13211323
// If an error happened here, it's likely that uploading the attachment
13221324
// failed, we'll can retry with the same events payload

packages/replay/test/unit/index.test.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ describe('Replay', () => {
581581
const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 3 };
582582

583583
// Suppress console.errors
584-
jest.spyOn(console, 'error').mockImplementation(jest.fn());
585-
const mockConsole = console.error as jest.MockedFunction<typeof console.error>;
584+
const mockConsole = jest.spyOn(console, 'error').mockImplementation(jest.fn());
586585

587586
// fail the first and second requests and pass the third one
588587
mockTransportSend.mockImplementationOnce(() => {
@@ -632,8 +631,7 @@ describe('Replay', () => {
632631
jest.spyOn(replay, 'sendReplay');
633632

634633
// Suppress console.errors
635-
jest.spyOn(console, 'error').mockImplementation(jest.fn());
636-
const mockConsole = console.error as jest.MockedFunction<typeof console.error>;
634+
const mockConsole = jest.spyOn(console, 'error').mockImplementation(jest.fn());
637635

638636
expect(replay.session?.segmentId).toBe(0);
639637

@@ -749,8 +747,7 @@ describe('Replay', () => {
749747
it('does not create replay event if recording upload completely fails', async () => {
750748
const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 3 };
751749
// Suppress console.errors
752-
jest.spyOn(console, 'error').mockImplementation(jest.fn());
753-
const mockConsole = console.error as jest.MockedFunction<typeof console.error>;
750+
const mockConsole = jest.spyOn(console, 'error').mockImplementation(jest.fn());
754751
// fail the first and second requests and pass the third one
755752
mockSendReplayRequest.mockImplementationOnce(() => {
756753
throw new Error('Something bad happened');

packages/replay/worker/src/handleMessage.ts

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export function handleMessage(e: MessageEvent): void {
5050
success: false,
5151
response: err,
5252
});
53+
54+
// eslint-disable-next-line no-console
5355
console.error(err);
5456
}
5557
}

0 commit comments

Comments
 (0)