Skip to content

Commit 4edac41

Browse files
authored
ref(serverless): Remove rethrowAfterCapture use in AWS lambda wrapper (#4448)
This PR removes the use of the `rethrowAfterCapture` option from the AWS handler-wrapping function `@sentry/serverless` provides. Without its use, the code follows the same path as it has been when the option has been set to its default value, which is `true`. Though this is _technically_ a breaking change for anyone who currently has it set to `false`, a) the option has never been documented, b) it never should have existed in the first place (we do error _monitoring_, not error _handling_, meaning there should be no question as to whether we rethrow the error after recording it), c) of all of the public projects on GH, only three are using it set explicitly to `true`, and zero are using it set to `false`. For the three projects using it set to `true`, there is no behavior change. Further, since all three are written in TS, the option hasn't been removed from the `WrapperOptions` type, so that their continuing to pass it doesn’t cause type errors. It has been made optional, though, so that our non-use of it also doesn't cause type errors. There's also a TODO so that we remember to remove it in v7. Fixes #3364.
1 parent 5c75be0 commit 4edac41

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

7+
This patch contains a breaking change for anyone setting the undocumented `rethrowAfterCapture` option for `@sentry/serverless`'s AWS wrapper to `false`, as its functionality has been removed. For backwards compatibility with anyone setting it to `true` (which is also the default), the option remains in the `WrapperOptions` type for now. It will be removed in the next major release, though, so we recommend removing it from your code.
8+
9+
- ref(serverless): Remove `rethrowAfterCapture` use in AWS lambda wrapper (#4448)
10+
711
## 6.17.1
812

913
- ref(core): Renormalize event only after stringification errors (#4425)
@@ -945,7 +949,7 @@ removed in the future. If you are only using the `Tracing` integration there is
945949

946950
## 5.6.3
947951

948-
- [browser] fix: Don't capture our own XHR events that somehow bubbled-up to global handler
952+
- [browser] fix: Don't capture our own XHR events that somehow bubbled-up to global handler (#2221)
949953

950954
## 5.6.2
951955

packages/serverless/src/awslambda.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export type AsyncHandler<T extends Handler> = (
4242

4343
export interface WrapperOptions {
4444
flushTimeout: number;
45-
rethrowAfterCapture: boolean;
45+
// TODO: DEPRECATED - remove `rethrowAfterCapture` in v7
46+
rethrowAfterCapture?: boolean;
4647
callbackWaitsForEmptyEventLoop: boolean;
4748
captureTimeoutWarning: boolean;
4849
timeoutWarningLimit: number;
@@ -215,11 +216,10 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTi
215216
export function wrapHandler<TEvent, TResult>(
216217
handler: Handler<TEvent, TResult>,
217218
wrapOptions: Partial<WrapperOptions> = {},
218-
): Handler<TEvent, TResult | undefined> {
219+
): Handler<TEvent, TResult> {
219220
const START_TIME = performance.now();
220221
const options: WrapperOptions = {
221222
flushTimeout: 2000,
222-
rethrowAfterCapture: true,
223223
callbackWaitsForEmptyEventLoop: false,
224224
captureTimeoutWarning: true,
225225
timeoutWarningLimit: 500,
@@ -293,7 +293,7 @@ export function wrapHandler<TEvent, TResult>(
293293

294294
const hub = getCurrentHub();
295295
const scope = hub.pushScope();
296-
let rv: TResult | undefined;
296+
let rv: TResult;
297297
try {
298298
enhanceScopeWithEnvironmentData(scope, context, START_TIME);
299299
// We put the transaction on the scope so users can attach children to it
@@ -309,9 +309,7 @@ export function wrapHandler<TEvent, TResult>(
309309
}
310310
} catch (e) {
311311
captureException(e);
312-
if (options.rethrowAfterCapture) {
313-
throw e;
314-
}
312+
throw e;
315313
} finally {
316314
clearTimeout(timeoutWarningTimer);
317315
transaction.finish();

packages/serverless/test/awslambda.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,6 @@ describe('AWSLambda', () => {
9191
expect(Sentry.flush).toBeCalledWith(1337);
9292
});
9393

94-
test('rethrowAfterCapture', async () => {
95-
expect.assertions(3);
96-
97-
const error = new Error('wat');
98-
const handler = () => {
99-
throw error;
100-
};
101-
const wrappedHandlerWithRethrow = wrapHandler(handler, { rethrowAfterCapture: true });
102-
const wrappedHandlerWithoutRethrow = wrapHandler(handler, { rethrowAfterCapture: false });
103-
104-
await expect(wrappedHandlerWithRethrow(fakeEvent, fakeContext, fakeCallback)).rejects.toThrow(error);
105-
await expect(wrappedHandlerWithoutRethrow(fakeEvent, fakeContext, fakeCallback)).resolves.not.toThrow();
106-
expect(Sentry.flush).toBeCalledTimes(2);
107-
});
108-
10994
test('captureTimeoutWarning enabled (default)', async () => {
11095
expect.assertions(2);
11196

0 commit comments

Comments
 (0)