Skip to content

debugger, errors: migrate to use internal/errors.js #11380

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<a id="nodejs-error-codes"></a>
## Node.js Error Codes

<a id="ERR_UNKNOWN_DEBUGGER_STATE"></a>
### ERR_UNKNOWN_DEBUGGER_STATE

The `'ERR_UNKNOWN_DEBUGGER_STATE'` error code is used to identify that the state of the debugger is not known.
Copy link
Member

@joyeecheung joyeecheung Feb 15, 2017

Choose a reason for hiding this comment

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

@shubheksha According to the history I think the test of this comes from #8454 and the code dates back to 8d82ec2, this looks like just a safety net in case anyone accidentally set the .state from outside and break the state machine, so probably we can add a sentence at the end: ...not known, possibly set by code outside the debugger module.

On another note, debugger module is deprecated and is going to be replaced by node inspect, so this error probably would not stay that long in the code base. Thanks for the contribution anyway!

Copy link
Member

Choose a reason for hiding this comment

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

Also can you add a line break in the sentence so it wraps in ~80 characters? Thanks!

3 changes: 2 additions & 1 deletion lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -126,7 +127,7 @@ Protocol.prototype.execute = function(d) {
break;

default:
throw new Error('Unknown state');
throw new errors.Error('ERR_UNKNOWN_DEBUGGER_STATE');
}
};

Expand Down
1 change: 1 addition & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_UNKNOWN_DEBUGGER_STATE', 'Unknown state');
4 changes: 2 additions & 2 deletions test/parallel/test-debug-protocol-execute.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');
const debug = require('_debugger');

Expand All @@ -16,5 +16,5 @@ assert.strictEqual(protocol.res.body, undefined);
protocol.state = 'sterrance';
assert.throws(
() => { protocol.execute('grumblecakes'); },
/^Error: Unknown state$/
common.expectsError('ERR_UNKNOWN_DEBUGGER_STATE', Error)
);