Skip to content

Commit 5d0094a

Browse files
authored
fix: Ensure all logs are wrapped with consoleSandbox (#13690)
To avoid infinite loops etc.
1 parent 69e7427 commit 5d0094a

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Inject, Injectable } from '@angular/core';
44
import * as Sentry from '@sentry/browser';
55
import type { ReportDialogOptions } from '@sentry/browser';
66
import type { Event } from '@sentry/types';
7-
import { isString } from '@sentry/utils';
7+
import { consoleSandbox, isString } from '@sentry/utils';
88

99
import { runOutsideAngular } from './zone';
1010

@@ -119,7 +119,7 @@ class SentryErrorHandler implements AngularErrorHandler, OnDestroy {
119119
// When in development mode, log the error to console for immediate feedback.
120120
if (this._options.logErrors) {
121121
// eslint-disable-next-line no-console
122-
console.error(extractedError);
122+
consoleSandbox(() => console.error(extractedError));
123123
}
124124

125125
// Optionally show user dialog to provide details on what happened.

packages/node/src/integrations/local-variables/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Debugger, InspectorNotification, Runtime } from 'node:inspector';
22
import { Session } from 'node:inspector/promises';
33
import { workerData } from 'node:worker_threads';
4+
import { consoleSandbox } from '@sentry/utils';
45
import type { LocalVariablesWorkerArgs, PausedExceptionEvent, RateLimitIncrement, Variables } from './common';
56
import { LOCAL_VARIABLES_KEY } from './common';
67
import { createRateLimiter } from './common';
@@ -10,7 +11,7 @@ const options: LocalVariablesWorkerArgs = workerData;
1011
function log(...args: unknown[]): void {
1112
if (options.debug) {
1213
// eslint-disable-next-line no-console
13-
console.log('[LocalVariables Worker]', ...args);
14+
consoleSandbox(() => console.log('[LocalVariables Worker]', ...args));
1415
}
1516
}
1617

packages/nuxt/src/module.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { addPlugin, addPluginTemplate, addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit';
2+
import { consoleSandbox } from '@sentry/utils';
23
import type { SentryNuxtModuleOptions } from './common/types';
34
import { addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';
45
import { setupSourceMaps } from './vite/sourceMaps';
@@ -70,10 +71,12 @@ export default defineNuxtModule<ModuleOptions>({
7071
addSentryTopImport(moduleOptions, nuxt);
7172
} else {
7273
if (moduleOptions.debug) {
73-
// eslint-disable-next-line no-console
74-
console.log(
75-
`[Sentry] Using your \`${serverConfigFile}\` file for the server-side Sentry configuration. In case you have a \`public/instrument.server\` file, the \`public/instrument.server\` file will be ignored. Make sure the file path in your node \`--import\` option matches the Sentry server config file in your \`.output\` folder and has a \`.mjs\` extension.`,
76-
);
74+
consoleSandbox(() => {
75+
// eslint-disable-next-line no-console
76+
console.log(
77+
`[Sentry] Using your \`${serverConfigFile}\` file for the server-side Sentry configuration. In case you have a \`public/instrument.server\` file, the \`public/instrument.server\` file will be ignored. Make sure the file path in your node \`--import\` option matches the Sentry server config file in your \`.output\` folder and has a \`.mjs\` extension.`,
78+
);
79+
});
7780
}
7881
}
7982
}

packages/nuxt/src/vite/addServerConfig.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs';
22
import { createResolver } from '@nuxt/kit';
33
import type { Nuxt } from '@nuxt/schema';
4+
import { consoleSandbox } from '@sentry/utils';
45
import type { SentryNuxtModuleOptions } from '../common/types';
56

67
/**
@@ -38,18 +39,22 @@ export function addServerConfigToBuild(
3839
await fs.promises.copyFile(source, destination);
3940

4041
if (moduleOptions.debug) {
41-
// eslint-disable-next-line no-console
42-
console.log(
43-
`[Sentry] Successfully added the content of the \`${serverConfigFile}\` file to \`${destination}\``,
44-
);
42+
consoleSandbox(() => {
43+
// eslint-disable-next-line no-console
44+
console.log(
45+
`[Sentry] Successfully added the content of the \`${serverConfigFile}\` file to \`${destination}\``,
46+
);
47+
});
4548
}
4649
} catch (error) {
4750
if (moduleOptions.debug) {
48-
// eslint-disable-next-line no-console
49-
console.warn(
50-
`[Sentry] An error occurred when trying to add the \`${serverConfigFile}\` file to the \`.output\` directory`,
51-
error,
52-
);
51+
consoleSandbox(() => {
52+
// eslint-disable-next-line no-console
53+
console.warn(
54+
`[Sentry] An error occurred when trying to add the \`${serverConfigFile}\` file to the \`.output\` directory`,
55+
error,
56+
);
57+
});
5358
}
5459
}
5560
});
@@ -72,20 +77,24 @@ export function addSentryTopImport(moduleOptions: SentryNuxtModuleOptions, nuxt:
7277

7378
fs.writeFile(entryFilePath, updatedContent, 'utf8', () => {
7479
if (moduleOptions.debug) {
75-
// eslint-disable-next-line no-console
76-
console.log(
77-
`[Sentry] Successfully added the Sentry import to the server entry file "\`${entryFilePath}\`"`,
78-
);
80+
consoleSandbox(() => {
81+
// eslint-disable-next-line no-console
82+
console.log(
83+
`[Sentry] Successfully added the Sentry import to the server entry file "\`${entryFilePath}\`"`,
84+
);
85+
});
7986
}
8087
});
8188
});
8289
} catch (err) {
8390
if (moduleOptions.debug) {
84-
// eslint-disable-next-line no-console
85-
console.warn(
86-
`[Sentry] An error occurred when trying to add the Sentry import to the server entry file "\`${entryFilePath}\`":`,
87-
err,
88-
);
91+
consoleSandbox(() => {
92+
// eslint-disable-next-line no-console
93+
console.warn(
94+
`[Sentry] An error occurred when trying to add the Sentry import to the server entry file "\`${entryFilePath}\`":`,
95+
err,
96+
);
97+
});
8998
}
9099
}
91100
});

packages/sveltekit/src/server/handleError.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { captureException } from '@sentry/node';
2+
import { consoleSandbox } from '@sentry/utils';
23
import type { HandleServerError } from '@sveltejs/kit';
34

45
import { flushIfServerless } from './utils';
@@ -8,7 +9,7 @@ import { flushIfServerless } from './utils';
89
function defaultErrorHandler({ error }: Parameters<HandleServerError>[0]): ReturnType<HandleServerError> {
910
// @ts-expect-error this conforms to the default implementation (including this ts-expect-error)
1011
// eslint-disable-next-line no-console
11-
console.error(error && error.stack);
12+
consoleSandbox(() => console.error(error && error.stack));
1213
}
1314

1415
type HandleServerErrorInput = Parameters<HandleServerError>[0];

0 commit comments

Comments
 (0)