Skip to content

fix: slice off all leading lines of multiline error message in clean() - #78

Open
chiragbitoni wants to merge 1 commit into
tapjs:mainfrom
chiragbitoni:fix/multiline-error-message
Open

chiragbitoni wants to merge 1 commit into
tapjs:mainfrom
chiragbitoni:fix/multiline-error-message

Conversation

@chiragbitoni

Copy link
Copy Markdown

Description

When cleaning a stack trace from an error with a multiline message (for example: throw new TypeError(foo\nbar\nbaz)), clean() previously tested:

if (!(/^s*at /.test(stack[0])) && (/^s*at /.test(stack[1]))) {
  stack = stack.slice(1);
}

Because stack[1] is another line of the message rather than an at frame, no lines were sliced off before the loop, and the last line of the multiline message (baz) was retained as lastNonAtLine and output before the first frame.

This PR uses stack.findIndex(line => /^\s*at /.test(line)) to locate the first frame index, slicing off all preceding lines belonging to the leading error message.

Fixes #53

Checklist

  • 100% tests pass with full code coverage
  • regression tests included
  • commit signed off with DCO

Previously, clean() checked if line 0 was not an at line and line 1 was an at line, assuming error messages were always a single line. When an error message spanned multiple lines, none of the message lines were sliced off before the loop, causing the last message line to be retained as a leading header before the first frame.

Use findIndex to locate the first at frame and slice off all preceding message lines.

Fixes tapjs#53

Signed-off-by: Chirag Bitoni <chiragbitoni4994@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

last line of leading multiline message remains in cleaned stack

1 participant