Skip to content

Do not stringify errors when logging them #19148

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 1 commit into from
Dec 6, 2024

Conversation

nicolo-ribaudo
Copy link
Contributor

Converting errors to string drops their stack trace, making it more difficult to debug their actual reason. We can instead pass the error objects as-is to console.warn/error, so that Firefox/Chrome devtools will show both the stack trace of the console.warn/error call, and the original stack trace of the error.

@Snuffleupagus
Copy link
Collaborator

If we're going to start using this pattern, then it probably wouldn't hurt to also enable the following ESLint rule: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-console-spaces.md

Converting errors to string drops their stack trace, making it more
difficult to debug their actual reason. We can instead pass the error
objects as-is to console.warn/error, so that Firefox/Chrome devtools
will show both the stack trace of the console.warn/error call, and the
original stack trace of the error.

This commit also enables the `unicorn/no-console-spaces` ESLint rule,
which avoids accidental extra spaces when passing multiple parameters to
`console.*` methods.
@nicolo-ribaudo
Copy link
Contributor Author

Seems reasonable, added.

@Snuffleupagus
Copy link
Collaborator

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/b624d1ad21a179f/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/6d3162e0c69d7cc/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/b624d1ad21a179f/output.txt

Total script time: 29.09 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/6d3162e0c69d7cc/output.txt

Total script time: 50.79 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: Passed

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me, thanks.

@Snuffleupagus Snuffleupagus merged commit c198e0b into mozilla:master Dec 6, 2024
7 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the error-preserve-trace branch December 6, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants