Skip to content

Better error handling of --js code for none error throws to close #822 - #828

Merged
mathiasrw merged 3 commits into
mainfrom
fix/822
Oct 23, 2026
Merged

mathiasrw merged 3 commits into
mainfrom
fix/822

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #822

Stacked on #827.

Change

--js code can throw anything, not only an error. The message is now made in a way that can not fail:

Code Before Now
throw Object.create(null) the error handling crashed, with a stack trace and exit code 1 an object was thrown
throw {code: 42} [object Object] an object was thrown: {"code":42}
throw "" an empty message an empty string was thrown
throw new Error("x") Error: x the same

Tests

test/fix/822.test.js is new, and 3 of its 4 tests fail without the fix. yarn test-ci passes.

From the review of 23 October.

After the review of 24 October

  • An error whose message can not be read is told by its name, like a TypeError was thrown.
  • A thrown object is cut after 300 chars, as it can hold a whole file.

After the review of 24 October

Closes #845

  • An object of a class of the user is told by its class and what it holds, like a Foo was thrown: {"a":1}. Before the last fix it lost the class, and after it, what it held.
  • The whole message is cut after 300 characters, by characters and not UTF-16 units, so an emoji is not split into �. That covers a long class name too.
  • "an" in front of a vowel: an Error was thrown, an Item was thrown.

@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 13:10
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 13:11
@mathiasrw
mathiasrw added this pull request to stack #842 October 23, 2026 13:57
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 14:14
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 14:20
@mathiasrw mathiasrw changed the title Give a message and not a crash when --js code throws something that is not an error to close #822 Fix the crash when --js code throws non-error objects to close #822 Oct 23, 2026
@mathiasrw
mathiasrw force-pushed the fix/822 branch 3 times, most recently from af7e975 to 8ae75e8 Compare October 23, 2026 15:54
Base automatically changed from fix/826 to main October 23, 2026 15:55
@mathiasrw mathiasrw changed the title Fix the crash when --js code throws non-error objects to close #822 Better error handling of --js code for none error throws to close #822 Oct 23, 2026
@mathiasrw
mathiasrw merged commit b1516f7 into main Oct 23, 2026
6 of 7 checks passed
@mathiasrw
mathiasrw deleted the fix/822 branch October 23, 2026 16:04
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.

Fix small things in the message when --js code throws something that is not an error Fix a crash when --js code throws something that is not an error

1 participant