Skip to content

ref: Avoid try-catch with unused parameter #17015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
es2017: true,
},
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
},
extends: ['@sentry-internal/sdk'],
ignorePatterns: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function getApproximateNumberOfTests(testPath: string): number {
const content = fs.readFileSync(path.join(process.cwd(), testPath, 'test.ts'), 'utf-8');
const matches = content.match(/sentryTest\(/g);
return Math.max(matches ? matches.length : 1, 1);
} catch (e) {
} catch {
console.error(`Could not read file ${testPath}`);
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sentryTest('should capture feedback with custom button', async ({ getLocalTestUr

try {
return getEnvelopeType(req) === 'feedback';
} catch (err) {
} catch {
return false;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {

try {
return getEnvelopeType(req) === 'feedback';
} catch (err) {
} catch {
return false;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sentryTest('should capture feedback', async ({ forceFlushReplay, getLocalTestUrl

try {
return getEnvelopeType(req) === 'feedback';
} catch (err) {
} catch {
return false;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {

try {
return getEnvelopeType(req) === 'feedback';
} catch (err) {
} catch {
return false;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Sentry.init({
moduleMetadataEntries.push(frame.module_metadata);
});
});
} catch (e) {
} catch {
// noop
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Sentry.init({
moduleMetadataEntries.push(frame.module_metadata);
});
});
} catch (e) {
} catch {
// noop
}
}
Expand Down
4 changes: 2 additions & 2 deletions dev-packages/browser-integration-tests/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const envelopeParser = (request: Request | null): unknown[] => {
return envelope.split('\n').map(line => {
try {
return JSON.parse(line);
} catch (error) {
} catch {
return line;
}
});
Expand Down Expand Up @@ -172,7 +172,7 @@ export async function runScriptInSandbox(
): Promise<void> {
try {
await page.addScriptTag({ path: impl.path, content: impl.content });
} catch (e) {
} catch {
// no-op
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class IndexController extends Controller {
public createCaughtEmberError(): void {
try {
throw new Error('Looks like you have a caught EmberError');
} catch (e) {
} catch {
// do nothing
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function CrashedPage() {
// @ts-expect-error
window.onerror(null, null, null, null, new Error('Crashed'));
}
} catch (_e) {
} catch {
// no-empty
}
return <h1>Crashed</h1>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getLatestNextVersion = async () => {
const response = await fetch('https://registry.npmjs.org/next/latest');
const data = await response.json();
return data.version as string;
} catch (error) {
} catch {
return '0.0.0';
}
};
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/node-core-integration-tests/scripts/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ for (const path of paths) {
// eslint-disable-next-line no-console
console.log(`docker compose down @ ${path}`);
execSync('docker compose down --volumes', { stdio: 'inherit', cwd: path });
} catch (_) {
} catch {
//
}
}
2 changes: 1 addition & 1 deletion dev-packages/node-core-integration-tests/utils/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export function createRunner(...paths: string[]) {
try {
const envelope = JSON.parse(cleanedLine) as Envelope;
newEnvelope(envelope);
} catch (_) {
} catch {
//
}
}
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/node-integration-tests/scripts/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ for (const path of paths) {
// eslint-disable-next-line no-console
console.log(`docker compose down @ ${path}`);
execSync('docker compose down --volumes', { stdio: 'inherit', cwd: path });
} catch (_) {
} catch {
//
}
}
2 changes: 1 addition & 1 deletion dev-packages/node-integration-tests/utils/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export function createRunner(...paths: string[]) {
try {
const envelope = JSON.parse(cleanedLine) as Envelope;
newEnvelope(envelope);
} catch (_) {
} catch {
//
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/patch-vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function wrapTestInZone(testBody: string | any[] | undefined) {
enumerable: false,
});
wrappedFunc.length = testBody.length;
} catch (e) {
} catch {
return testBody.length === 0
? () => testProxyZone.run(testBody, null)
: (done: any) => testProxyZone.run(testBody, null, [done]);
Expand Down
8 changes: 4 additions & 4 deletions packages/aws-serverless/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe('AWSLambda', () => {

try {
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
} catch (e) {
} catch {
const fakeTransactionContext = {
name: 'functionName',
op: 'function.aws.lambda',
Expand Down Expand Up @@ -376,7 +376,7 @@ describe('AWSLambda', () => {

try {
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
} catch (e) {
} catch {
const fakeTransactionContext = {
name: 'functionName',
op: 'function.aws.lambda',
Expand Down Expand Up @@ -458,7 +458,7 @@ describe('AWSLambda', () => {

try {
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
} catch (e) {
} catch {
const fakeTransactionContext = {
name: 'functionName',
op: 'function.aws.lambda',
Expand Down Expand Up @@ -489,7 +489,7 @@ describe('AWSLambda', () => {

try {
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
} catch (e) {
} catch {
expect(mockCaptureException).toBeCalledWith(error, expect.any(Function));

const scopeFunction = mockCaptureException.mock.calls[0][1];
Expand Down
8 changes: 4 additions & 4 deletions packages/browser-utils/src/instrument/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function instrumentDOM(): void {
}

handlerForType.refCount++;
} catch (e) {
} catch {
// Accessing dom properties is always fragile.
// Also allows us to skip `addEventListeners` calls with no proper `this` context.
}
Expand Down Expand Up @@ -120,7 +120,7 @@ export function instrumentDOM(): void {
delete this.__sentry_instrumentation_handlers__;
}
}
} catch (e) {
} catch {
// Accessing dom properties is always fragile.
// Also allows us to skip `addEventListeners` calls with no proper `this` context.
}
Expand Down Expand Up @@ -148,7 +148,7 @@ function isSimilarToLastCapturedEvent(event: Event): boolean {
if (!event.target || (event.target as SentryWrappedTarget)._sentryId !== lastCapturedEventTargetId) {
return false;
}
} catch (e) {
} catch {
// just accessing `target` property can throw an exception in some rare circumstances
// see: https://github.com/getsentry/sentry-javascript/issues/838
}
Expand Down Expand Up @@ -236,7 +236,7 @@ function makeDOMEventHandler(
function getEventTarget(event: Event): SentryWrappedTarget | null {
try {
return event.target as SentryWrappedTarget | null;
} catch (e) {
} catch {
// just accessing `target` property can throw an exception in some rare circumstances
// see: https://github.com/getsentry/sentry-javascript/issues/838
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-utils/src/instrument/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function instrumentXHR(): void {
// touching statusCode in some platforms throws
// an exception
xhrInfo.status_code = xhrOpenThisArg.status;
} catch (e) {
} catch {
/* do nothing */
}

Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/eventbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function parseStackFrames(

try {
return stackParser(stacktrace, skipLines, framesToPop);
} catch (e) {
} catch {
// no-empty
}

Expand Down Expand Up @@ -392,7 +392,7 @@ function getObjectClassName(obj: unknown): string | undefined | void {
try {
const prototype: Prototype | null = Object.getPrototypeOf(obj);
return prototype ? prototype.constructor.name : undefined;
} catch (e) {
} catch {
// ignore errors here
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function wrap<T extends WrappableFunction, NonFunction>(
if (getOriginalFunction(fn)) {
return fn;
}
} catch (e) {
} catch {
// Just accessing custom props in some Selenium environments
// can cause a "Permission denied" exception (see raven-js#495).
// Bail on wrapping and return the function as-is (defers to window.onerror).
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function _getDomBreadcrumbHandler(

target = htmlTreeAsString(element, { keyAttrs, maxStringLength });
componentName = getComponentName(element);
} catch (e) {
} catch {
target = '<unknown>';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/integrations/browserapierrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function _wrapEventTarget(target: string, integrationOptions: BrowserApiErrorsOp
if (originalEventHandler) {
originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
}
} catch (e) {
} catch {
// ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
}
return originalRemoveEventListener.call(this, eventName, fn, options);
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/tracing/linkedTraces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export function getPreviousTraceFromSessionStorage(): PreviousTraceInfo | undefi
const previousTraceInfo = WINDOW.sessionStorage?.getItem(PREVIOUS_TRACE_KEY);
// @ts-expect-error - intentionally risking JSON.parse throwing when previousTraceInfo is null to save bundle size
return JSON.parse(previousTraceInfo);
} catch (e) {
} catch {
return undefined;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/tracing/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export function shouldAttachHeaders(
try {
resolvedUrl = new URL(targetUrl, href);
currentOrigin = new URL(href).origin;
} catch (e) {
} catch {
return false;
}

Expand Down Expand Up @@ -413,7 +413,7 @@ function setHeaderOnXhr(
xhr.setRequestHeader!('baggage', sentryBaggageHeader);
}
}
} catch (_) {
} catch {
// Error: InvalidStateError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/transports/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ function createIndexedDbStore(options: BrowserOfflineTransportOptions): OfflineS
try {
const serialized = await serializeEnvelope(env);
await push(getStore(), serialized, options.maxQueueSize || 30);
} catch (_) {
} catch {
//
}
},
unshift: async (env: Envelope) => {
try {
const serialized = await serializeEnvelope(env);
await unshift(getStore(), serialized, options.maxQueueSize || 30);
} catch (_) {
} catch {
//
}
},
Expand All @@ -147,7 +147,7 @@ function createIndexedDbStore(options: BrowserOfflineTransportOptions): OfflineS
if (deserialized) {
return parseEnvelope(deserialized);
}
} catch (_) {
} catch {
//
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
}

// This is here because Miniflare sometimes cannot get instrumented
} catch (e) {
} catch {
// Do not console anything here, we don't want to spam the console with errors
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/instrument/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async function resolveResponse(res: Response | undefined, onFinishedResolving: (
onFinishedResolving();
readingActive = false;
}
} catch (error) {
} catch {
readingActive = false;
} finally {
clearTimeout(chunkTimeout);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/integrations/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const _dedupeIntegration = (() => {
DEBUG_BUILD && debug.warn('Event dropped due to being a duplicate of previously captured event.');
return null;
}
} catch (_oO) {} // eslint-disable-line no-empty
} catch {} // eslint-disable-line no-empty

return (previousEvent = currentEvent);
},
Expand Down Expand Up @@ -170,7 +170,7 @@ function _isSameFingerprint(currentEvent: Event, previousEvent: Event): boolean
// Otherwise, compare the two
try {
return !!(currentFingerprint.join('') === previousFingerprint.join(''));
} catch (_oO) {
} catch {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/integrations/eventFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function _getEventFilterUrl(event: Event): string | null {
.find(value => value.mechanism?.parent_id === undefined && value.stacktrace?.frames?.length);
const frames = rootException?.stacktrace?.frames;
return frames ? _getLastValidUrl(frames) : null;
} catch (oO) {
} catch {
DEBUG_BUILD && debug.error(`Cannot extract url for event ${getEventDescription(event)}`);
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/integrations/rewriteframes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const rewriteFramesIntegration = defineIntegration((options: RewriteFrame
})),
},
};
} catch (_oO) {
} catch {
return event;
}
}
Expand Down
Loading
Loading