From 27eafce5f5d827e2d43b1b2bf6da2278bbed3907 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 17:49:25 +0200 Subject: [PATCH 1/7] doc: add semicolons in errors.md code examples --- doc/api/errors.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 640935da35e460..e55bec2d733436 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -149,7 +149,7 @@ function nodeStyleCallback(err, data) { } fs.readFile('/some/file/that/does-not-exist', nodeStyleCallback); -fs.readFile('/some/file/that/does-exist', nodeStyleCallback) +fs.readFile('/some/file/that/does-exist', nodeStyleCallback); ``` The JavaScript `try / catch` mechanism **cannot** be used to intercept errors @@ -217,7 +217,7 @@ a string representing the location in the code at which ```js const myObject = {}; Error.captureStackTrace(myObject); -myObject.stack // similar to `new Error().stack` +myObject.stack; // similar to `new Error().stack` ``` The first line of the trace, instead of being prefixed with `ErrorType: @@ -238,7 +238,7 @@ function MyError() { // Without passing MyError to captureStackTrace, the MyError // frame would show up in the .stack property. By passing // the constructor, we omit that frame and all frames above it. -new MyError().stack +new MyError().stack; ``` ### Error.stackTraceLimit From dd46df60e25667bf5d7507168e2cc7ce1f1c5763 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 17:51:37 +0200 Subject: [PATCH 2/7] doc: fix indentation in errors.md code example --- doc/api/errors.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index e55bec2d733436..3a710f052dd3d6 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -141,11 +141,11 @@ the first argument will be passed as `null`. const fs = require('fs'); function nodeStyleCallback(err, data) { - if (err) { - console.error('There was an error', err); - return; - } - console.log(data); + if (err) { + console.error('There was an error', err); + return; + } + console.log(data); } fs.readFile('/some/file/that/does-not-exist', nodeStyleCallback); From 292801ac0a8f0fcda890ccea69de2986481c4995 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 17:54:04 +0200 Subject: [PATCH 3/7] doc: add spaces in errors.md code examples --- doc/api/errors.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 3a710f052dd3d6..e6a5b354f97b9f 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -167,7 +167,7 @@ try { throw err; } }); -} catch(err) { +} catch (err) { // This will not catch the throw! console.log(err); } @@ -175,7 +175,7 @@ try { This will not work because the callback function passed to `fs.readFile()` is called asynchronously. By the time the callback has been called, the -surrounding code (including the `try { } catch(err) { }` block will have +surrounding code (including the `try { } catch (err) { }` block will have already exited. Throwing an error inside the callback **can crash the Node.js process** in most cases. If [domains][] are enabled, or a handler has been registered with `process.on('uncaughtException')`, such errors can be @@ -387,7 +387,7 @@ that was not defined. const assert = require('assert'); try { doesNotExist; -} catch(err) { +} catch (err) { assert(err.arguments[0], 'doesNotExist'); } ``` @@ -407,7 +407,7 @@ program. ```js try { require('vm').runInThisContext('binary ! isNotOk'); -} catch(err) { +} catch (err) { // err will be a SyntaxError } ``` From f89aea83b91e80f7d6e64608b475e25c4ec4f465 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 17:56:17 +0200 Subject: [PATCH 4/7] doc: console.log() -> console.error() in errors.md --- doc/api/errors.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index e6a5b354f97b9f..bb53a413c47b16 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -169,7 +169,7 @@ try { }); } catch (err) { // This will not catch the throw! - console.log(err); + console.error(err); } ``` @@ -267,7 +267,7 @@ the stack trace of the `Error`, however changing this property after the ```js const err = new Error('The message'); -console.log(err.message); +console.error(err.message); // Prints: The message ``` From 5a1cfac2d5f39f748ebd2884ce60773feb729d4b Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 17:58:25 +0200 Subject: [PATCH 5/7] doc: fix level of headings in errors.md --- doc/api/errors.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index bb53a413c47b16..c72be251afbc9a 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -255,7 +255,7 @@ will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. -#### error.message +### error.message * {String} @@ -271,7 +271,7 @@ console.error(err.message); // Prints: The message ``` -#### error.stack +### error.stack * {String} From 94fd761995ac0116f2b7b2987304849d381fbe89 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 18:00:05 +0200 Subject: [PATCH 6/7] doc: update comment in errors.md code example --- doc/api/errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index c72be251afbc9a..f163f87536c787 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -359,7 +359,7 @@ For example: ```js require('net').connect(-1); - // throws RangeError, port should be > 0 && < 65536 + // throws "RangeError: "port" option should be >= 0 and < 65536: -1" ``` Node.js will generate and throw `RangeError` instances *immediately* as a form From eb2c7c07d19b8058a45f2e37ea56b47468700e82 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 18:03:28 +0200 Subject: [PATCH 7/7] doc: delete obsolete info and example in errors.md Fixes: https://github.com/nodejs/node/issues/11558 --- doc/api/errors.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index f163f87536c787..e0e0f06ac5900f 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -379,19 +379,6 @@ doesNotExist; // throws ReferenceError, doesNotExist is not a variable in this program. ``` -`ReferenceError` instances will have an `error.arguments` property whose value -is an array containing a single element: a string representing the variable -that was not defined. - -```js -const assert = require('assert'); -try { - doesNotExist; -} catch (err) { - assert(err.arguments[0], 'doesNotExist'); -} -``` - Unless an application is dynamically generating and running code, `ReferenceError` instances should always be considered a bug in the code or its dependencies.