Skip to content
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

lib: externalized messages support #4311

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b187d16
src: externalized messages support, 2nd pass
jasnell Jan 7, 2016
6401743
src: externalize debugger.js messages
jasnell Jan 8, 2016
3fcddc4
src: externalized _debug_agent.js messages
jasnell Jan 8, 2016
503092e
test, src: add test-internal-messages.js, address nits
jasnell Jan 8, 2016
4359ec9
src: fix lint issue
jasnell Jan 8, 2016
c48ec49
src: externalize lib/_http_agent.js messages
jasnell Jan 8, 2016
112b084
src: externalize _http_client.js messages
jasnell Jan 8, 2016
8538841
src: externalize _http_outgoing.js messages, address nits
jasnell Jan 8, 2016
ff170ed
src: remove NODE_ prefix from message identifiers
jasnell Jan 8, 2016
bdca377
src: externalize _http_server.js messages
jasnell Jan 8, 2016
b270571
src: externalize _linklist.js messages
jasnell Jan 8, 2016
1b1e228
src: externalize _stream_readable.js messages
jasnell Jan 8, 2016
ee2228d
src: externalize _stream_transform.js messages
jasnell Jan 8, 2016
71d1fae
src: externalize _stream_wrap.js messages
jasnell Jan 8, 2016
eb882bc
src: externalized _stream_writable.js messages
jasnell Jan 8, 2016
0de2994
tools: enable restParams for eslint
jasnell Jan 8, 2016
0f0298e
src: externalize _tls_legacy.js messages, refactor debug
jasnell Jan 8, 2016
f095579
src: externalize _tls_wrap.js messages
jasnell Jan 9, 2016
62f6ec9
src: externalize assert.js messages
jasnell Jan 9, 2016
5d73fb3
src: externalize buffer.js messages
jasnell Jan 9, 2016
b1bc41f
src: externalize child-process.js messages
jasnell Jan 9, 2016
018472b
src: externalize cluster.js messages
jasnell Jan 9, 2016
7aa5d4f
src: externalize console.js messages
jasnell Jan 9, 2016
20640e8
src: externalize crypto.js messages
jasnell Jan 9, 2016
78b9090
src: externalize dgram.js messages
jasnell Jan 9, 2016
82679a5
src: externalize dns.js messages
jasnell Jan 9, 2016
649721b
src: externalize events.js messages
jasnell Jan 9, 2016
11b96dc
src: externalize fs.js messages
jasnell Jan 9, 2016
abc08a9
src: externalize http.js messages
jasnell Jan 9, 2016
0b9c3af
src: externalize https.js messages
jasnell Jan 9, 2016
0e8b40a
src: externalize module.js messages
jasnell Jan 9, 2016
650ab1c
src: externalize net.js messages
jasnell Jan 9, 2016
d89c414
src: externalize os.js messages
jasnell Jan 9, 2016
181e5c6
src: externalize path.js messages
jasnell Jan 9, 2016
b1ca5e1
src: externalize punycode.js messages
jasnell Jan 9, 2016
55fa5d8
src: externalize readline.js messages
jasnell Jan 9, 2016
5f4861d
src: externalize repl.js messages
jasnell Jan 9, 2016
67185ec
src: externalize string_decoder.js messages
jasnell Jan 9, 2016
f0c5782
src: externalize sys.js messages
jasnell Jan 9, 2016
497329f
src: externalized timers.js messages
jasnell Jan 9, 2016
e142e8a
src: externalize tls.js messages
jasnell Jan 9, 2016
678e8e8
src: externalize url.js messages
jasnell Jan 9, 2016
0a197c8
src: externalize util.js messages
jasnell Jan 9, 2016
cd4db97
src: externalize zlib.js messages
jasnell Jan 9, 2016
61240ea
src: externalize internal/child_process.js messages
jasnell Jan 9, 2016
259a36d
src: externalize internal/repl.js messages
jasnell Jan 9, 2016
96aa61f
src: externalize internal/socket_list.js messages
jasnell Jan 9, 2016
b885af3
src: externalize internal/v8_prof_polyfill.js messages
jasnell Jan 9, 2016
924aa9d
src: externalize additional messages missed
jasnell Jan 9, 2016
086bd73
src: avoid runtime calls
jasnell Jan 9, 2016
46fcb2d
src: code cleanup
jasnell Jan 9, 2016
edcb53b
src: refactor I18N.Error, I18N.TypeError and I18N.RangeError
jasnell Jan 10, 2016
42b7c7f
src: internal/messages.js code cleanup
jasnell Jan 10, 2016
21b1d95
src: begin externalizing src/* messages
jasnell Jan 10, 2016
5545855
src: externalize more native strings
jasnell Jan 11, 2016
08866a3
src: support varargs in messages, externalize src/node_dtrace.cc
jasnell Jan 11, 2016
44cc074
src: refactor macros to make env explicit, externalize node_file.cc
jasnell Jan 11, 2016
a5d97de
src: externalize additional src/*.cc files
jasnell Jan 11, 2016
9fc6ec1
src: externalize remaining errors in src/*.cc
jasnell Jan 11, 2016
92df8e6
src: externalize node.cc messages and print help, cleanups
jasnell Jan 11, 2016
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ecmaFeatures:
objectLiteralShorthandProperties: true
octalLiterals: true
templateStrings: true
restParams: true

rules:
# Possible Errors
Expand Down
9 changes: 5 additions & 4 deletions lib/_debug_agent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const I18N = require('internal/messages');
const assert = require('assert');
const net = require('net');
const util = require('util');
Expand All @@ -20,7 +21,7 @@ exports.start = function start() {

agent.listen(process._debugAPI.port, function() {
var addr = this.address();
process._rawDebug('Debugger listening on port %d', addr.port);
process._rawDebug(I18N(I18N.DEBUGAGENT_LISTENING, addr.port));
process._debugAPI.notifyListen();
});

Expand Down Expand Up @@ -57,7 +58,7 @@ function Agent() {
};

this.clients = [];
assert(this.binding, 'Debugger agent running without bindings!');
assert(this.binding, I18N(I18N.DEBUGAGENT_NO_BINDINGS));
}
util.inherits(Agent, net.Server);

Expand Down Expand Up @@ -132,15 +133,15 @@ Client.prototype._transform = function _transform(data, enc, cb) {
// Header-name: header-value\r\n
var match = this.buffer.match(/^([^:\s\r\n]+)\s*:\s*([^\s\r\n]+)\r\n/);
if (!match)
return this.destroy('Expected header, but failed to parse it');
return this.destroy(I18N(I18N.DEBUGAGENT_EXPECTED_HEADER));

this.headers[match[1].toLowerCase()] = match[2];

this.buffer = this.buffer.slice(match[0].length);
} else {
var len = this.headers['content-length'];
if (len === undefined)
return this.destroy('Expected content-length');
return this.destroy(I18N(I18N.DEBUGAGENT_EXPECTED_CONTENT_LENGTH));

len = len | 0;
if (Buffer.byteLength(this.buffer) < len)
Expand Down
93 changes: 50 additions & 43 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const I18N = require('internal/messages');
const internalUtil = require('internal/util');
const util = require('util');
const path = require('path');
Expand All @@ -12,13 +13,16 @@ const assert = require('assert');
const spawn = require('child_process').spawn;
const Buffer = require('buffer').Buffer;

const USAGE = `${I18N(I18N.DEBUGGER_USAGE)}:
node debug script.js
node debug <host>:<port>
node debug -p <pid>`;

exports.start = function(argv, stdin, stdout) {
argv || (argv = process.argv.slice(2));

if (argv.length < 1) {
console.error('Usage: node debug script.js');
console.error(' node debug <host>:<port>');
console.error(' node debug -p <pid>');
console.error(USAGE);
process.exit(1);
}

Expand All @@ -32,8 +36,8 @@ exports.start = function(argv, stdin, stdout) {
stdin.resume();

process.on('uncaughtException', function(e) {
internalUtil.error('There was an internal error in Node\'s debugger. ' +
'Please report this bug.');
// Report internal error
internalUtil.error(I18N(I18N.DEBUGGER_ERROR));
console.error(e.message);
console.error(e.stack);
if (interface_.child) interface_.child.kill();
Expand Down Expand Up @@ -126,7 +130,7 @@ Protocol.prototype.execute = function(d) {
break;

default:
throw new Error('Unknown state');
throw new I18N.Error(I18N.DEBUGGER_UNKNOWN_STATE);
}
};

Expand All @@ -135,8 +139,7 @@ Protocol.prototype.serialize = function(req) {
req.type = 'request';
req.seq = this.reqSeq++;
var json = JSON.stringify(req);
return 'Content-Length: ' + Buffer.byteLength(json, 'utf8') +
'\r\n\r\n' + json;
return `Content-Length: ${Buffer.byteLength(json, 'utf8')}\r\n\r\n${json}`;
};


Expand Down Expand Up @@ -521,7 +524,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
cb = cb || function() {};
this.reqLookup(propertyRefs, function(err, res) {
if (err) {
internalUtil.error('problem with reqLookup');
internalUtil.error(I18N(I18N.DEBUGGER_PROBLEM_REQLOOKUP));
cb(null, handle);
return;
}
Expand Down Expand Up @@ -598,7 +601,8 @@ Client.prototype.fullTrace = function(cb) {
cb = cb || function() {};
this.reqBacktrace(function(err, trace) {
if (err) return cb(err);
if (trace.totalFrames <= 0) return cb(Error('No frames'));
if (trace.totalFrames <= 0)
return cb(new I18N.Error(I18N.DEBUGGER_NO_FRAMES));

var refs = [];

Expand Down Expand Up @@ -669,11 +673,8 @@ const commands = [
]
];


var helpMessage = 'Commands: ' + commands.map(function(group) {
return group.join(', ');
}).join(',\n');

var cmdList = commands.map((group) => group.join(', ')).join(',\n');
var helpMessage = `${I18N(I18N.DEBUGGER_COMMANDS)}: ${cmdList}`;

function SourceUnderline(sourceText, position, repl) {
if (!sourceText) return '';
Expand All @@ -695,7 +696,9 @@ function SourceUnderline(sourceText, position, repl) {


function SourceInfo(body) {
var result = body.exception ? 'exception in ' : 'break in ';
var result = body.exception ?
I18N(I18N.DEBUGGER_EXCEPTION_IN) :
I18N(I18N.DEBUGGER_BREAK_IN);

if (body.script) {
if (body.script.name) {
Expand Down Expand Up @@ -932,7 +935,7 @@ Interface.prototype.handleBreak = function(r) {
// Internal method for checking connection state
Interface.prototype.requireConnection = function() {
if (!this.client) {
this.error('App isn\'t running... Try `run` instead');
this.error(I18N(I18N.DEBUGGER_APP_NOT_RUNNING));
return false;
}
return true;
Expand Down Expand Up @@ -1038,7 +1041,7 @@ Interface.prototype.run = function() {
var callback = arguments[0];

if (this.child) {
this.error('App is already running... Try `restart` instead');
this.error(I18N(I18N.DEBUGGER_APP_RUNNING));
callback && callback(true);
} else {
this.trySpawn(callback);
Expand Down Expand Up @@ -1094,7 +1097,7 @@ Interface.prototype.list = function(delta) {
self.pause();
client.reqSource(from, to, function(err, res) {
if (err || !res) {
self.error('You can\'t list source code right now');
self.error(I18N(I18N.DEBUGGER_CANNOT_LIST_SOURCE));
self.resume();
return;
}
Expand Down Expand Up @@ -1153,13 +1156,13 @@ Interface.prototype.backtrace = function() {
self.pause();
client.fullTrace(function(err, bt) {
if (err) {
self.error('Can\'t request backtrace now');
self.error(I18N(I18N.DEBUGGER_CANNOT_REQUEST_BACKTRACE));
self.resume();
return;
}

if (bt.totalFrames == 0) {
self.print('(empty stack)');
self.print(I18N(I18N.DEBUGGER_EMPTY_STACK));
} else {
var trace = [],
firstFrameNative = bt.frames[0].script.isNative;
Expand Down Expand Up @@ -1296,7 +1299,7 @@ Interface.prototype.watchers = function() {

function wait() {
if (--waiting === 0) {
if (verbose) self.print('Watchers:');
if (verbose) self.print(`${I18N(I18N.DEBUGGER_WATCHERS)}: `);

self._watchers.forEach(function(watcher, i) {
self.print(leftPad(i, ' ', self._watchers.length - 1) +
Expand Down Expand Up @@ -1348,8 +1351,7 @@ Interface.prototype.setBreakpoint = function(script, line,
}

if (script === undefined) {
this.print('Cannot determine the current script, ' +
'make sure the debugged process is paused.');
this.print(I18N(I18N.DEBUGGER_CANNOT_DETERMINE_SCRIPT));
return;
}

Expand Down Expand Up @@ -1378,8 +1380,10 @@ Interface.prototype.setBreakpoint = function(script, line,
scriptId = script;
}

if (ambiguous) return this.error('Script name is ambiguous');
if (line <= 0) return this.error('Line should be a positive value');
if (ambiguous)
return this.error(I18N(I18N.DEBUGGER_SCRIPT_NAME_AMBIGUOUS));
if (line <= 0)
return this.error(I18N(I18N.DEBUGGER_LINE_POSITIVE));

var req;
if (scriptId) {
Expand All @@ -1390,7 +1394,7 @@ Interface.prototype.setBreakpoint = function(script, line,
condition: condition
};
} else {
this.print('Warning: script \'' + script + '\' was not loaded yet.');
this.print(I18N(I18N.DEBUGGER_SCRIPT_NOT_LOADED, script));
var escapedPath = script.replace(/([/\\.?*()^${}|[\]])/g, '\\$1');
var scriptPathRegex = '^(.*[\\/\\\\])?' + escapedPath + '$';
req = {
Expand Down Expand Up @@ -1472,15 +1476,14 @@ Interface.prototype.clearBreakpoint = function(script, line) {
}
}

if (ambiguous) return this.error('Script name is ambiguous');
if (ambiguous)
return this.error(I18N(I18N.DEBUGGER_SCRIPT_NAME_AMBIGUOUS));

if (scriptId === undefined) {
return this.error('Script ' + script + ' not found');
}
if (scriptId === undefined)
return this.error(I18N(I18N.DEBUGGER_SCRIPT_NOT_FOUND, script));

if (breakpoint === undefined) {
return this.error('Breakpoint not found on line ' + line);
}
if (breakpoint === undefined)
return this.error(I18N(I18N.DEBUGGER_BREAKPOINT_NOT_FOUND, line));

var self = this,
req = {
Expand Down Expand Up @@ -1560,7 +1563,7 @@ Interface.prototype.repl = function() {

var self = this;

self.print('Press Ctrl + C to leave debug repl');
self.print(I18N(I18N.DEBUGGER_REPL_EXIT));

// Don't display any default messages
var listeners = this.repl.rli.listeners('SIGINT').slice(0);
Expand Down Expand Up @@ -1671,7 +1674,7 @@ Interface.prototype.trySpawn = function(cb) {
process._debugProcess(pid);
} catch (e) {
if (e.code === 'ESRCH') {
internalUtil.error(`Target process: ${pid} doesn't exist.`);
internalUtil.error(I18N(I18N.DEBUGGER_TARGET_PROCESS, pid));
process.exit(1);
}
throw e;
Expand Down Expand Up @@ -1702,17 +1705,18 @@ Interface.prototype.trySpawn = function(cb) {
connectionAttempts = 0;

client.once('ready', function() {
self.stdout.write(' ok\n');
self.stdout.write(` ${I18N(I18N.DEBUGGER_READY)}\n`);

// Restore breakpoints
breakpoints.forEach(function(bp) {
self.print('Restoring breakpoint ' + bp.scriptReq + ':' + bp.line);
self.print(`${I18N(I18N.DEBUGGER_RESTORING_BREAKPOINT)} ` +
`${bp.scriptReq}:${bp.line}`);
self.setBreakpoint(bp.scriptReq, bp.line, bp.condition, true);
});

client.on('close', function() {
self.pause();
self.print('program terminated');
self.print(I18N(I18N.DEBUGGER_PROGRAM_TERMINATED));
self.resume();
self.client = null;
self.killChild();
Expand All @@ -1724,7 +1728,8 @@ Interface.prototype.trySpawn = function(cb) {

client.on('unhandledResponse', function(res) {
self.pause();
self.print('\nunhandled res:' + JSON.stringify(res));
self.print(`\n${I18N(I18N.DEBUGGER_UNHANDLED_RESPONSE)}: ` +
`${JSON.stringify(res)}`);
self.resume();
});

Expand All @@ -1740,7 +1745,7 @@ Interface.prototype.trySpawn = function(cb) {
function connectError() {
// If it's failed to connect 10 times then print failed message
if (connectionAttempts >= 10) {
internalUtil.error(' failed to connect, please retry');
internalUtil.error(I18N(I18N.DEBUGGER_CONNECTION_FAILED));
process.exit(1);
}
setTimeout(attemptConnect, 500);
Expand All @@ -1753,11 +1758,13 @@ Interface.prototype.trySpawn = function(cb) {
}

if (isRemote) {
self.print('connecting to ' + host + ':' + port + ' ..', true);
self.print(`${I18N(I18N.DEBUGGER_CONNECTING)} ${host}:${port} ..`,
true);
attemptConnect();
} else {
this.child.stderr.once('data', function() {
self.print('connecting to ' + host + ':' + port + ' ..', true);
self.print(`${I18N(I18N.DEBUGGER_CONNECTING)} ${host}:${port} ..`,
true);
setImmediate(attemptConnect);
});
}
Expand Down
Loading