From cc987936f032bbecab6ba36fe46fc8b55eaa40d8 Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Tue, 14 Feb 2017 17:24:52 +0530 Subject: [PATCH 1/4] doc: add documentation for new error added --- doc/api/errors.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/api/errors.md b/doc/api/errors.md index 640935da35e460..164097dc75f6e8 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -575,9 +575,18 @@ found [here][online]. [domains]: domain.html [event emitter-based]: events.html#events_class_eventemitter [file descriptors]: https://en.wikipedia.org/wiki/File_descriptor +[Node.js Error Codes]: #nodejs-error-codes [online]: http://man7.org/linux/man-pages/man3/errno.3.html [stream-based]: stream.html [syscall]: http://man7.org/linux/man-pages/man2/syscall.2.html [try-catch]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch [V8's stack trace API]: https://github.com/v8/v8/wiki/Stack-Trace-API [vm]: vm.html + + +## Node.js Error Codes + + +### ERR_INVALID_CALLBACK + +The `'ERR_UNK_STATE'` error code is used to identify that the current state is not known. \ No newline at end of file From 6f012ec4a887bd3e634f0dbc7602ab4701594696 Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Tue, 14 Feb 2017 23:49:45 +0530 Subject: [PATCH 2/4] debugger, test: migrate to internal/errors Use the new error code defined in internal/errors for _debugger.js --- lib/_debugger.js | 3 ++- lib/internal/errors.js | 1 + test/parallel/test-debug-protocol-execute.js | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/_debugger.js b/lib/_debugger.js index d3bf1f9ffa2dab..690dcd29014365 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -11,6 +11,7 @@ const inherits = util.inherits; const assert = require('assert'); const spawn = require('child_process').spawn; const Buffer = require('buffer').Buffer; +const errors = require('internal/errors'); exports.start = function(argv, stdin, stdout) { argv || (argv = process.argv.slice(2)); @@ -126,7 +127,7 @@ Protocol.prototype.execute = function(d) { break; default: - throw new Error('Unknown state'); + throw new errors.Error('ERR_UNK_STATE'); } }; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index f2376f70371c60..d55357625ee2f0 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -86,3 +86,4 @@ module.exports = exports = { // Note: Please try to keep these in alphabetical order E('ERR_ASSERTION', (msg) => msg); // Add new errors from here... +E('ERR_UNK_STATE', 'Unknown state'); diff --git a/test/parallel/test-debug-protocol-execute.js b/test/parallel/test-debug-protocol-execute.js index 2283a3c54e9034..eec113b921bf74 100644 --- a/test/parallel/test-debug-protocol-execute.js +++ b/test/parallel/test-debug-protocol-execute.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const debug = require('_debugger'); @@ -16,5 +16,5 @@ assert.strictEqual(protocol.res.body, undefined); protocol.state = 'sterrance'; assert.throws( () => { protocol.execute('grumblecakes'); }, - /^Error: Unknown state$/ + common.expectsError('ERR_UNK_STATE', Error) ); From 86adefae9c835dc47be4df5f78b965c662c75f8b Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Wed, 15 Feb 2017 02:01:26 +0530 Subject: [PATCH 3/4] replace ERR_UNK_STATE with ERR_UNKNOWN_DEBUGGER_STATE Add more explanation for the error code and replace it with a more verbose alternative --- doc/api/errors.md | 6 +++--- lib/_debugger.js | 2 +- lib/internal/errors.js | 2 +- test/parallel/test-debug-protocol-execute.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 164097dc75f6e8..a5ee320688880a 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -586,7 +586,7 @@ found [here][online]. ## Node.js Error Codes - -### ERR_INVALID_CALLBACK + +### ERR_UNKNOWN_DEBUGGER_STATE -The `'ERR_UNK_STATE'` error code is used to identify that the current state is not known. \ No newline at end of file +The `'ERR_UNKNOWN_DEBUGGER_STATE'` error code is used to identify that the state of the debugger is not known. \ No newline at end of file diff --git a/lib/_debugger.js b/lib/_debugger.js index 690dcd29014365..e784c029614cf3 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -127,7 +127,7 @@ Protocol.prototype.execute = function(d) { break; default: - throw new errors.Error('ERR_UNK_STATE'); + throw new errors.Error('ERR_UNKNOWN_DEBUGGER_STATE'); } }; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index d55357625ee2f0..3d764bed34d33c 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -86,4 +86,4 @@ module.exports = exports = { // Note: Please try to keep these in alphabetical order E('ERR_ASSERTION', (msg) => msg); // Add new errors from here... -E('ERR_UNK_STATE', 'Unknown state'); +E('ERR_UNKNOWN_DEBUGGER_STATE', 'Unknown state'); diff --git a/test/parallel/test-debug-protocol-execute.js b/test/parallel/test-debug-protocol-execute.js index eec113b921bf74..9311b7a5a50ce0 100644 --- a/test/parallel/test-debug-protocol-execute.js +++ b/test/parallel/test-debug-protocol-execute.js @@ -16,5 +16,5 @@ assert.strictEqual(protocol.res.body, undefined); protocol.state = 'sterrance'; assert.throws( () => { protocol.execute('grumblecakes'); }, - common.expectsError('ERR_UNK_STATE', Error) + common.expectsError('ERR_UNKNOWN_DEBUGGER_STATE', Error) ); From 692a8d44cf987eb8c57acec8238968abe09e7a82 Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Wed, 15 Feb 2017 13:44:07 +0530 Subject: [PATCH 4/4] docs: make the explanation more descriptive - Added more documentation about ERR_UNKNOWN_DEBUGGER_STATE error code --- doc/api/errors.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index a5ee320688880a..61d739e6486eb9 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -589,4 +589,5 @@ found [here][online]. ### ERR_UNKNOWN_DEBUGGER_STATE -The `'ERR_UNKNOWN_DEBUGGER_STATE'` error code is used to identify that the state of the debugger is not known. \ No newline at end of file +The `'ERR_UNKNOWN_DEBUGGER_STATE'` error code is used to identify that the state +of the debugger is not known, possibly set by code outside the debugger module. \ No newline at end of file