-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
alternative stack trace approach #2119
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b503aec
reimpl getDefinitionLineAndUri
davidjgoss ab4415b
Merge branch 'main' into feat/nodejs-source-maps
davidjgoss fa80d80
disable current stack trace filtering
davidjgoss 9f4ff1d
filter stack traces without modifying error
davidjgoss ce0fccb
rename file
davidjgoss d62aa68
rename file
davidjgoss 01938e3
add advice about source maps
davidjgoss d69c47c
Merge branch 'main' into feat/nodejs-source-maps
davidjgoss 515f93a
Merge branch 'main' into feat/nodejs-source-maps
davidjgoss c2fc0df
WIP feature for transpiled stack traces
davidjgoss ce039a3
Merge branch 'main' into feat/nodejs-source-maps
davidjgoss 519b704
improve feature for transpiled stack traces
davidjgoss 388f758
skip source-mapping scenarios when instrumenting with nyc
davidjgoss 31785e2
Merge branch 'main' into feat/nodejs-source-maps
davidjgoss 17215a8
merge main
davidjgoss ef19e77
update CHANGELOG.md
davidjgoss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import path from 'path' | ||
import { valueOrDefault } from './value_checker' | ||
import { StackFrame } from 'error-stack-parser' | ||
|
||
const projectRootPath = path.join(__dirname, '..') | ||
const projectChildDirs = ['src', 'lib', 'node_modules'] | ||
|
||
export function isFileNameInCucumber(fileName: string): boolean { | ||
return projectChildDirs.some((dir) => | ||
fileName.startsWith(path.join(projectRootPath, dir)) | ||
) | ||
} | ||
|
||
export function filterStackTrace(frames: StackFrame[]): StackFrame[] { | ||
if (isErrorInCucumber(frames)) { | ||
return frames | ||
} | ||
const index = frames.findIndex((x) => isFrameInCucumber(x)) | ||
if (index === -1) { | ||
return frames | ||
} | ||
return frames.slice(0, index) | ||
} | ||
|
||
function isErrorInCucumber(frames: StackFrame[]): boolean { | ||
const filteredFrames = frames.filter((x) => !isFrameInNode(x)) | ||
return filteredFrames.length > 0 && isFrameInCucumber(filteredFrames[0]) | ||
} | ||
|
||
function isFrameInCucumber(frame: StackFrame): boolean { | ||
const fileName = valueOrDefault(frame.getFileName(), '') | ||
return isFileNameInCucumber(fileName) | ||
} | ||
|
||
function isFrameInNode(frame: StackFrame): boolean { | ||
const fileName = valueOrDefault(frame.getFileName(), '') | ||
return !fileName.includes(path.sep) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { format } from 'assertion-error-formatter' | ||
import errorStackParser from 'error-stack-parser' | ||
import { filterStackTrace } from '../filter_stack_trace' | ||
|
||
export function formatError(error: Error, filterStackTraces: boolean): string { | ||
let filteredStack: string | ||
if (filterStackTraces) { | ||
try { | ||
filteredStack = filterStackTrace(errorStackParser.parse(error)) | ||
.map((f) => f.source) | ||
.join('\n') | ||
} catch { | ||
// if we weren't able to parse and filter, we'll settle for the original | ||
} | ||
} | ||
return format(error, { | ||
colorFns: { | ||
errorStack: (stack: string) => | ||
filteredStack ? `\n${filteredStack}` : stack, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kind of abusing the
assertion-error-formatter
API here, which doesn't feel great. It could maybe do with aformatErrorStack
option where you can provide a function that rewrites the stack as desired?