-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Conversation
Ideally I'd like to backport this to v0.10 as well -- should I open another PR for that? |
This partially addresses #8103. |
ReferenceError instances will have an `.arguments` member that is an array containing | ||
one element -- a string representing the variable that was not defined. | ||
|
||
try { |
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.
Any reason not to enable syntax highlighting?
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.
Ah, I'm following the style of existing docs. I'm not sure that the build setup for the docs enables github flavored markdown. Maybe something to look into in a subsequent PR?
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 thought they did, Streams has syntax highlighting at an rate
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.
Ah! Good catch. I was looking at the http docs. I'll add that!
this looks rad @chrisdickinson! |
#### error.stack | ||
|
||
A property that, when **accessed**, returns a string representing the point in the program | ||
at which this error was instantiated. An example stacktrace follows: |
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.
This and line 51 one read a bit oddly
A general error object -- its imparts no meaning to the situation that | ||
generated the error. Errors capture a "stack trace" detailing the point | ||
in the program at which they were instantiated, and may provide an | ||
description of the error. |
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.
s/an description/a description
@tjfontaine - could I ask you to do a quick final review? |
|
||
<!--type=class--> | ||
|
||
A general error object -- its imparts no meaning to the situation that |
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.
typo "its imparts"
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.
Good eye! Thanks!
Needs an eye of some native-english core contributor: @trevnorris or @tjfontaine |
|
||
<!--type=misc--> | ||
|
||
Errors generated by Node.JS fall into two categories: JavaScript errors and system |
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.
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.
"System errors" doesn't make a lot of sense, as I would clasify these as unrecoverable exceptions. For example, JS FATAL ALLOCATION
. Nothing you can do about that, and it's not an instanceof Error
.
There are also a set of recoverable and unrecoverable JS errors that are emitted from V8. For example:
process.on('uncaughtException', function(er) {
console.log(er);
});
var b = f;
// output: [ReferenceError: f is not defined]
So V8 allows the ReferenceError
to be caught. But in the following:
process.on('uncaughtException', function(er) {
console.log(er);
});
var b = f f;
There is no ability to recover, the following is printed and the application exits.
/tmp/test-exception.js:5
var b = f f;
^
SyntaxError: Unexpected identifier
at exports.runInThisContext (vm.js:69:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:124:16)
at node.js:811:3
So the SyntaxError
is still an instanceof Error
, but it's unrecoverable.
Bringing this back around. There are JS Error objects, and there are recoverable and unrecoverable exceptions.
All recoverable exceptions from Node.js and V8 will be an instanceof Error
, but not all unrecoverable exceptions. This does not imply that all recoverable exceptions are instanceof Error
, since anything can be thrown in JS. For example throw 42;
will propagate the number 42
to be caught, and it's not instanceof Error
.
That being said, the only reason that all recoverable exceptions thrown from Node.js and V8 are instanceof Error
is by convention. There's nothing forcing Node to only throw Error
objects.
This make sense?
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.
Addendum: Only V8 is allowed to throw unrecoverable exceptions that are also instanceof Error
.
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 think what you might have been going for with "system error" is like when fs.stat('not/here', cb)
passes the system error of ENOENT
. That entire mechanism has been setup by Node and is not fundamentally tied to the language or the idea of an exception.
Instead it should probably be explained separately that Node will wrap these types of "system errors" in a js error object so it can be inspected by the user. But it's dependent on the user having made a proper API call.
@chrisdickinson This is coming together quite nicely. 👏👏👏 |
message. Its `.stack` will represent the point in the program at which `new Error` | ||
was called. Stack traces are subject to [V8's stack trace API](https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi). | ||
Stack traces only extend as far back as the current event loop tick, *or* a number of frames given by | ||
`Error.stackTraceLimit`, whichever is smaller. |
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.
as far back as the current event loop tick
"to the beginning of synchronous code execution"
|
||
The location information will be one of: | ||
|
||
* `native`, if the frame represents a call internal to V8. |
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.
Again, specify that "native" here means js function built into V8. It doesn't include transversal through C++ "native" functions.
Wanted to address some general guidelines writing documentation:
As far as helping users understand the nature of "errors". They are broken up into the following:
Thanks for all your work on this. It will be nice to have a formative document explaining these specifics. |
@dshaw Thanks! @trevnorris Thanks for your review. I initially shied away from explaining the distinction between exceptions and errors: it's hard to balance between what is Node's responsibility to explain vs. what should be covered by more JS specific material (like MDN, the spec, YDKJS, et al). Ultimately, though, since the document touches on error propagation, it has to at least build a common vocabulary regarding exceptions, errors, propagation strategies, and system- vs. language-level errors. Some structural rework is in order -- I'll work on another draft incorporating your comments. Apologies for the copious number of emdashes -- it's a particular weakness of my writing. :) Re: Unrecoverable errors: is there an underlying concept of unrecoverable errors in v8, or is this a higher-level concept? |
@chrisdickinson Thanks for putting up with all my comments. :)
First let's specify, we're addressing unrecoverable exceptions (note: there's no such thing as an unrecoverable error) that are thrown as part of the V8 JS VM. Some exceptions thrown by V8 are recoverable. Some aren't. (This was discussed in #8114 (comment)). It simply means that the exception isn't caught by the V8 exception handling API that's exposed. Basically it's forcing the running JS context to be brought down. As you showed in your I'd like to revise my complicated list on how these are broken down:
I feel that is a better delineation of the set of pertinent topics, and while I agree there is plenty of material that properly explains the difference between errors and exceptions, there should at least be a brief mention in the documentation. Probably followed by links to more in-depth materials. Thanks again for all your hard work on this. :) |
@chrisdickinson ... what do you want to do with this one? |
This landed in io.js/converged node right? If so, I think we should just close this. |
I'm good with that! @chrisdickinson , closing this but can reopen if there's something we missed. |
This adds documentation around what errors are generated by Node and how to intercept them.
The rendered docs are available here.