util: Change how Error objects are formatted by zeusdeux · Pull Request #4582 · nodejs/node (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation20 Commits1 Checks0 Files changed
Conversation
This file contains hidden or 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
[ Show hidden characters]({{ revealButtonHref }})
Previously, Error objects were formatted as the result of a toString
call bounded by square brackets. They are now formatted as the stack
trace for the given error object. The intention initially was to emulate
how browsers do console.error
but since that would also impactconsole.warn
, console.log
, etc, it was decided to make the change atutil.inspect
level which is in turn used by the console
package.
This is definitely a semver-major change.
Bigger discussion @ #4452
Issues and PRs related to the built-in util module.
PRs that contain breaking changes and should be released in the next major version.
labels
@@ -55,13 +55,16 @@ assert.equal(util.format('%%%s%%%%', 'hi'), '%hi%%'); |
---|
})(); |
// Errors |
assert.equal(util.format(new Error('foo')), '[Error: foo]'); |
const err = new Error('foo'); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're working in this file, can you change the require()
statements at the top to use const
as well?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this in both test-util-format.js and test-util-inspect.js.
LGTM
But I'd like to get other @nodejs/ctc opinions also
LGTM-ish in that I think it's a useful change. Less LGTM in that it probably doesn't format well when you util.inspect()
an object graph with an Error object a few levels deep.
@bnoordhuis It does format kinda weird when there is an error object as a part of another object/array but the behaviour is now similar to that in browsers. It looks something like below:
{ a: 10, b: { c: 'nope', d: Error at repl:1:40 at REPLServer.defaultEval (repl.js:252:27) at bound (domain.js:287:14) at REPLServer.runBound [as eval] (domain.js:300:12) at REPLServer. (repl.js:417:12) at emitOne (events.js:83:20) at REPLServer.emit (events.js:170:7) at REPLServer.Interface._onLine (readline.js:215:10) at REPLServer.Interface._line (readline.js:554:8) at REPLServer.Interface._ttyWrite (readline.js:831:14) } }
Previously, Error objects were formatted as the result of a toString
call bounded by square brackets. They are now formatted as the stack
trace for the given error object. The intention initially was to emulate
how browsers do console.error
but since that would also impact
console.warn
, console.log
, etc, it was decided to make the change at
util.inspect
level which is in turn used by the console
package.
Fixes: nodejs#4452
@@ -488,7 +488,7 @@ function formatPrimitiveNoColor(ctx, value) { |
---|
function formatError(value) { |
return '[' + Error.prototype.toString.call(value) + ']'; |
return value.stack | |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added fallback in case the error is some custom error that isn't capturing the stack correctly.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a regression test for that? EDIT: Nevermind, I see BadCustomError covers that.
LGTM. One more sign-off would be good.
1 similar comment
jasnell pushed a commit that referenced this pull request
Previously, Error objects were formatted as the result of a toString
call bounded by square brackets. They are now formatted as the stack
trace for the given error object. The intention initially was to emulate
how browsers do console.error
but since that would also impact
console.warn
, console.log
, etc, it was decided to make the change at
util.inspect
level which is in turn used by the console
package.
Fixes: #4452 PR-URL: #4582 Reviewed-By: Ben Noordhuis info@bnoordhuis.nl Reviewed-By: Trevor Norris trev.norris@gmail.com Reviewed-By: Colin Ihrig cjihrig@gmail.com Reviewed-By: James M Snell jasnell@gmail.com
scovetta pushed a commit to scovetta/node that referenced this pull request
Previously, Error objects were formatted as the result of a toString
call bounded by square brackets. They are now formatted as the stack
trace for the given error object. The intention initially was to emulate
how browsers do console.error
but since that would also impact
console.warn
, console.log
, etc, it was decided to make the change at
util.inspect
level which is in turn used by the console
package.
Fixes: nodejs#4452 PR-URL: nodejs#4582 Reviewed-By: Ben Noordhuis info@bnoordhuis.nl Reviewed-By: Trevor Norris trev.norris@gmail.com Reviewed-By: Colin Ihrig cjihrig@gmail.com Reviewed-By: James M Snell jasnell@gmail.com
jasnell added a commit that referenced this pull request
The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.
- Buffer
- Cluster
- Worker emitted as first argument in 'message' event #5361.
- Crypto
- Dependencies
- DNS
- Add resolvePtr API to query plain DNS PTR records #4921.
- Domains
- Clear stack when no error handler #4659.
- File System
- The
fs.realpath()
andfs.realpathSync()
methods have been updated to use a more efficient libuv implementation. This change includes the removal of thecache
argument and the method can throw new errors #3594 - FS apis can now accept and return paths as Buffers #5616.
- Error handling and type checking improvements #5616, #5590, #4518, #3917.
- fs.read's string interface is deprecated #4525
- The
- HTTP
- 'clientError' can now be used to return custom errors from an HTTP server #4557.
- Modules
- Net
- Path
- Improved type checking #5348.
- Process
- Readline
- Emit key info unconditionally #6024
- REPL
- Assignment to
_
will emit a warning. #5535
- Assignment to
- Timers
- Fail early when callback is not a function #4362
- TLS
- TTY
- Previously deprecated setRawMode wrapper is removed #2528.
- Util
- Changes to Error object formatting #4582.
- Windows
jasnell added a commit that referenced this pull request
The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.
- Buffer
- Cluster
- Worker emitted as first argument in 'message' event #5361.
- Crypto
- Dependencies
- DNS
- Add resolvePtr API to query plain DNS PTR records #4921.
- Domains
- Clear stack when no error handler #4659.
- File System
- The
fs.realpath()
andfs.realpathSync()
methods have been updated to use a more efficient libuv implementation. This change includes the removal of thecache
argument and the method can throw new errors #3594 - FS apis can now accept and return paths as Buffers #5616.
- Error handling and type checking improvements #5616, #5590, #4518, #3917.
- fs.read's string interface is deprecated #4525
- The
- HTTP
- 'clientError' can now be used to return custom errors from an HTTP server #4557.
- Modules
- Net
- Path
- Improved type checking #5348.
- Process
- Readline
- Emit key info unconditionally #6024
- REPL
- Assignment to
_
will emit a warning. #5535
- Assignment to
- Timers
- Fail early when callback is not a function #4362
- TLS
- TTY
- Previously deprecated setRawMode wrapper is removed #2528.
- Util
- Changes to Error object formatting #4582.
- Windows
jasnell added a commit that referenced this pull request
The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.
- Buffer
- Cluster
- Worker emitted as first argument in 'message' event #5361.
- Crypto
- Dependencies
- DNS
- Add resolvePtr API to query plain DNS PTR records #4921.
- Domains
- Clear stack when no error handler #4659.
- File System
- The
fs.realpath()
andfs.realpathSync()
methods have been updated to use a more efficient libuv implementation. This change includes the removal of thecache
argument and the method can throw new errors #3594 - FS apis can now accept and return paths as Buffers #5616.
- Error handling and type checking improvements #5616, #5590, #4518, #3917.
- fs.read's string interface is deprecated #4525
- The
- HTTP
- 'clientError' can now be used to return custom errors from an HTTP server #4557.
- Modules
- Net
- OS X
- MACOSX_DEPLOYMENT_TARGET has been bumped up to 10.7 #6402.
- Path
- Improved type checking #5348.
- Process
- Readline
- Emit key info unconditionally #6024
- REPL
- Assignment to
_
will emit a warning. #5535
- Assignment to
- Timers
- Fail early when callback is not a function #4362
- TLS
- TTY
- Previously deprecated setRawMode wrapper is removed #2528.
- Util
- Changes to Error object formatting #4582.
- Windows
jasnell added a commit that referenced this pull request
The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.
- Buffer
- Cluster
- Worker emitted as first argument in 'message' event #5361.
- Crypto
- Dependencies
- DNS
- Add resolvePtr API to query plain DNS PTR records #4921.
- Domains
- Clear stack when no error handler #4659.
- File System
- The
fs.realpath()
andfs.realpathSync()
methods have been updated to use a more efficient libuv implementation. This change includes the removal of thecache
argument and the method can throw new errors #3594 - FS apis can now accept and return paths as Buffers #5616.
- Error handling and type checking improvements #5616, #5590, #4518, #3917.
- fs.read's string interface is deprecated #4525
- The
- HTTP
- 'clientError' can now be used to return custom errors from an HTTP server #4557.
- Modules
- Net
- OS X
- MACOSX_DEPLOYMENT_TARGET has been bumped up to 10.7 #6402.
- Path
- Improved type checking #5348.
- Process
- Readline
- Emit key info unconditionally #6024
- REPL
- Assignment to
_
will emit a warning. #5535
- Assignment to
- Timers
- Fail early when callback is not a function #4362
- TLS
- TTY
- Previously deprecated setRawMode wrapper is removed #2528.
- Util
- Changes to Error object formatting #4582.
- Windows
jasnell added a commit that referenced this pull request
The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.
- Buffer
- Cluster
- Worker emitted as first argument in 'message' event #5361.
- Crypto
- Dependencies
- DNS
- Add resolvePtr API to query plain DNS PTR records #4921.
- Domains
- Clear stack when no error handler #4659.
- File System
- The
fs.realpath()
andfs.realpathSync()
methods have been updated to use a more efficient libuv implementation. This change includes the removal of thecache
argument and the method can throw new errors #3594 - FS apis can now accept and return paths as Buffers #5616.
- Error handling and type checking improvements #5616, #5590, #4518, #3917.
- fs.read's string interface is deprecated #4525
- The
- HTTP
- 'clientError' can now be used to return custom errors from an HTTP server #4557.
- Modules
- Net
- OS X
- MACOSX_DEPLOYMENT_TARGET has been bumped up to 10.7 #6402.
- Path
- Improved type checking #5348.
- Process
- Readline
- Emit key info unconditionally #6024
- REPL
- Assignment to
_
will emit a warning. #5535
- Assignment to
- Timers
- Fail early when callback is not a function #4362
- TLS
- TTY
- Previously deprecated setRawMode wrapper is removed #2528.
- Util
- Changes to Error object formatting #4582.
- Windows
mcous mentioned this pull request
Labels
PRs that contain breaking changes and should be released in the next major version.
Issues and PRs related to the built-in util module.