Browse Source

child_process: add errno property to exceptions

In case of a write failure when using fork() an error would be thrown. The
thrown exception was missing the `errno` property.
v0.7.4-release
Andreas Madsen 13 years ago
committed by Bert Belder
parent
commit
ca6ededbd1
  1. 10
      lib/child_process.js

10
lib/child_process.js

@ -132,7 +132,7 @@ function setupChannel(target, channel) {
var writeReq = channel.write(buffer, 0, buffer.length, sendHandle); var writeReq = channel.write(buffer, 0, buffer.length, sendHandle);
if (!writeReq) { if (!writeReq) {
throw new Error(errno + 'cannot write to IPC channel.'); throw errnoException(errno, 'write', 'cannot write to IPC channel.');
} }
writeReq.oncomplete = nop; writeReq.oncomplete = nop;
@ -471,11 +471,15 @@ ChildProcess.prototype.spawn = function(options) {
}; };
function errnoException(errorno, syscall) { function errnoException(errorno, syscall, errmsg) {
// TODO make this more compatible with ErrnoException from src/node.cc // TODO make this more compatible with ErrnoException from src/node.cc
// Once all of Node is using this function the ErrnoException from // Once all of Node is using this function the ErrnoException from
// src/node.cc should be removed. // src/node.cc should be removed.
var e = new Error(syscall + ' ' + errorno); var message = syscall + ' ' + errorno;
if (errmsg) {
message += ' - ' + errmsg;
}
var e = new Error(message);
e.errno = e.code = errorno; e.errno = e.code = errorno;
e.syscall = syscall; e.syscall = syscall;
return e; return e;

Loading…
Cancel
Save