Skip to content

ref(node): Refactor node stack parsing to use common parser #4612

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 65 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
31935f0
node stackwalk for Electron
timfish Jun 20, 2021
781312e
Merge branch 'master' into feat/node-stackwalk-electron
timfish Jun 21, 2021
f143c10
Re-order params
timfish Jun 21, 2021
c890809
Merge branch 'master' into feat/node-stackwalk-electron
timfish Jun 21, 2021
8b30a9a
Move source loading to seperate file
timfish Jun 21, 2021
f1e3f31
First try
timfish Jun 22, 2021
6a03a2c
Improve logic
timfish Jun 22, 2021
7c164dd
Revert tslib change
timfish Jun 22, 2021
f362589
jsdoc
timfish Jun 22, 2021
da256ee
Merge branch 'master' into feat/separate-source-reading
timfish Jun 22, 2021
04db3fb
Merge branch 'master' into feat/separate-source-reading
timfish Jul 16, 2021
3324578
With integration
timfish Jul 20, 2021
443ea06
oops
timfish Jul 20, 2021
dcd287d
Merge branch 'master' into feat/separate-source-reading
timfish Aug 10, 2021
84155de
Make this a non-breaking change by keeping NodeOptions.frameContextLines
timfish Aug 10, 2021
285a643
Merge branch 'master' into feat/separate-source-reading
timfish Aug 24, 2021
6a8a48b
Merge remote-tracking branch 'upstream/master' into feat/separate-sou…
timfish Nov 3, 2021
c4f48ad
Merge remote-tracking branch 'upstream/master' into feat/separate-sou…
timfish Dec 1, 2021
7f5793a
Merge branch 'master' into feat/separate-source-reading
timfish Dec 1, 2021
ac4318e
Correctly handle zero lines of context
timfish Dec 1, 2021
82573f4
Merge remote-tracking branch 'origin/feat/separate-source-reading' in…
timfish Dec 1, 2021
86e2d4e
Make async
timfish Dec 1, 2021
2ff7efd
Merge branch 'master' into feat/separate-source-reading
timfish Dec 2, 2021
012eff3
Merge remote-tracking branch 'upstream/master' into feat/separate-sou…
timfish Jan 11, 2022
647999d
Merge remote-tracking branch 'upstream/master' into feat/separate-sou…
timfish Jan 21, 2022
2fe44fc
Merge remote-tracking branch 'upstream/master' into feat/separate-sou…
timfish Feb 8, 2022
af9b1d8
No longer a breaking change
timfish Feb 8, 2022
270e13e
Fix linting
timfish Feb 8, 2022
76d8998
Merge branch 'master' into feat/separate-source-reading
timfish Feb 13, 2022
ddb8406
Add docs and `@deprecated`
timfish Feb 14, 2022
83f859b
Disable warning for internal usage of deprecated field
timfish Feb 14, 2022
8bc20b0
Revert promise changes
timfish Feb 14, 2022
18c5780
Merge remote-tracking branch 'upstream/master' into feat/separate-sou…
timfish Feb 14, 2022
2266ac5
Minor improve
timfish Feb 15, 2022
bb37b6c
Merge remote-tracking branch 'upstream/master' into feat/separate-sou…
timfish Feb 16, 2022
03cb320
Fix nextjs test
timfish Feb 16, 2022
965d48f
revert
timfish Feb 16, 2022
e08bcbb
Fix nextjs test
timfish Feb 16, 2022
7cd79af
Merge branch 'feat/separate-source-reading' of https://github.com/tim…
timfish Feb 16, 2022
f278e8b
Code review changes!
timfish Feb 17, 2022
a7d61df
Merge remote-tracking branch 'upstream/master' into feat/separate-sou…
timfish Feb 17, 2022
069244f
Use common parser
timfish Feb 17, 2022
ef7d423
Abhi code review
timfish Feb 17, 2022
a172765
Revert promisify
timfish Feb 18, 2022
bd85ce9
Add TODO comment
timfish Feb 18, 2022
224090c
Merge branch 'feat/separate-source-reading' into node/refactor-stack-…
timfish Feb 21, 2022
e060c3c
no zero
timfish Feb 21, 2022
ba2400d
Only set stacktrace if frames are returned
timfish Feb 21, 2022
ab19826
Merge remote-tracking branch 'upstream/master' into node/refactor-sta…
timfish Feb 23, 2022
ae696b9
Merge remote-tracking branch 'upstream/master' into node/refactor-sta…
timfish Feb 23, 2022
e0ca922
Couple of minor improvements
timfish Feb 23, 2022
0ea2155
Doh
timfish Feb 23, 2022
2bc3bc9
More minor improvements
timfish Feb 23, 2022
6b57641
Allow the parser to mostly work when require is not available
timfish Feb 23, 2022
b54d7cf
chore: add issue forms (#4617)
vladanpaunovic Feb 23, 2022
b7966ce
Don't do the funky require thing
timfish Feb 23, 2022
81f7352
Merge remote-tracking branch 'upstream/master' into node/refactor-sta…
timfish Feb 23, 2022
73cbc09
webpack hates optional chaining?
timfish Feb 24, 2022
93e0293
Include comment about optional chaining
timfish Feb 24, 2022
386b80b
Remove unnecessary try catch
timfish Feb 24, 2022
e867d7c
Merge remote-tracking branch 'upstream/master' into node/refactor-sta…
timfish Feb 24, 2022
19dadbb
Fix bad merge
timfish Feb 24, 2022
c69db78
Rename stack parser
timfish Feb 24, 2022
2dc38e6
Re-add forked comments
timfish Feb 24, 2022
1379939
Fix the lineno
timfish Feb 24, 2022
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
8 changes: 4 additions & 4 deletions packages/node/src/backend.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseBackend } from '@sentry/core';
import { Event, EventHint, Severity, Transport, TransportOptions } from '@sentry/types';
import { makeDsn } from '@sentry/utils';
import { makeDsn, resolvedSyncPromise } from '@sentry/utils';

import { eventFromException, eventFromMessage } from './eventbuilder';
import { eventFromError, eventFromMessage } from './eventbuilder';
import { HTTPSTransport, HTTPTransport } from './transports';
import { NodeOptions } from './types';

Expand All @@ -16,14 +16,14 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
public eventFromException(exception: any, hint?: EventHint): PromiseLike<Event> {
return eventFromException(exception, hint);
return resolvedSyncPromise(eventFromError(exception, hint));
}

/**
* @inheritDoc
*/
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
return eventFromMessage(this._options, message, level, hint);
return resolvedSyncPromise(eventFromMessage(this._options, message, level, hint));
}

/**
Expand Down
76 changes: 48 additions & 28 deletions packages/node/src/eventbuilder.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
import { getCurrentHub } from '@sentry/hub';
import { Event, EventHint, Mechanism, Options, Severity } from '@sentry/types';
import { Event, EventHint, Exception, Mechanism, Options, Severity, StackFrame } from '@sentry/types';
import {
addExceptionMechanism,
addExceptionTypeValue,
createStackParser,
extractExceptionKeysForMessage,
isError,
isPlainObject,
normalizeToSize,
SyncPromise,
} from '@sentry/utils';

import { extractStackFromError, parseError, parseStack, prepareFramesForEvent } from './parsers';
import { node } from './stack-parser';

/**
* Extracts stack frames from the error.stack string
*/
export function extractStackFromError(error: Error): StackFrame[] {
return createStackParser(node)(error.stack || '');
}

/**
* Extracts stack frames from the error and builds a Sentry Exception
*/
export function exceptionFromError(error: Error): Exception {
const exception: Exception = {
type: error.name || error.constructor.name,
value: error.message,
};

const frames = extractStackFromError(error);
if (frames.length) {
exception.stacktrace = { frames };
}

return exception;
}

/**
* Builds and Event from a Exception
* @hidden
*/
export function eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
export function eventFromError(exception: unknown, hint?: EventHint): Event {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let ex: any = exception;
const providedMechanism: Mechanism | undefined =
Expand Down Expand Up @@ -47,19 +71,19 @@ export function eventFromException(exception: unknown, hint?: EventHint): Promis
mechanism.synthetic = true;
}

return new SyncPromise<Event>((resolve, reject) =>
parseError(ex as Error)
.then(event => {
addExceptionTypeValue(event, undefined, undefined);
addExceptionMechanism(event, mechanism);
const event = {
exception: {
values: [exceptionFromError(ex as Error)],
},
};

resolve({
...event,
event_id: hint && hint.event_id,
});
})
.then(null, reject),
);
addExceptionTypeValue(event, undefined, undefined);
addExceptionMechanism(event, mechanism);

return {
...event,
event_id: hint && hint.event_id,
};
}

/**
Expand All @@ -71,23 +95,19 @@ export function eventFromMessage(
message: string,
level: Severity = Severity.Info,
hint?: EventHint,
): PromiseLike<Event> {
): Event {
const event: Event = {
event_id: hint && hint.event_id,
level,
message,
};

return new SyncPromise<Event>(resolve => {
if (options.attachStacktrace && hint && hint.syntheticException) {
const stack = hint.syntheticException ? extractStackFromError(hint.syntheticException) : [];
const frames = parseStack(stack);
event.stacktrace = {
frames: prepareFramesForEvent(frames),
};
resolve(event);
} else {
resolve(event);
if (options.attachStacktrace && hint && hint.syntheticException) {
const frames = extractStackFromError(hint.syntheticException);
if (frames.length) {
event.stacktrace = { frames };
}
});
}

return event;
}
15 changes: 6 additions & 9 deletions packages/node/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
import { Event, EventHint, Exception, ExtendedError, Integration } from '@sentry/types';
import { isInstanceOf, resolvedSyncPromise, SyncPromise } from '@sentry/utils';

import { getExceptionFromError } from '../parsers';
import { exceptionFromError } from '../eventbuilder';

const DEFAULT_KEY = 'cause';
const DEFAULT_LIMIT = 5;
Expand Down Expand Up @@ -80,15 +80,12 @@ export class LinkedErrors implements Integration {
if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) {
return resolvedSyncPromise(stack);
}

const exception = exceptionFromError(error[key]);

return new SyncPromise<Exception[]>((resolve, reject) => {
void getExceptionFromError(error[key])
.then((exception: Exception) => {
void this._walkErrorTree(error[key], key, [exception, ...stack])
.then(resolve)
.then(null, () => {
reject();
});
})
void this._walkErrorTree(error[key], key, [exception, ...stack])
.then(resolve)
.then(null, () => {
reject();
});
Expand Down
148 changes: 0 additions & 148 deletions packages/node/src/parsers.ts

This file was deleted.

Loading