From ca6ededbd1af5cc759ec98952b84c0b34edb2d40 Mon Sep 17 00:00:00 2001 From: Andreas Madsen Date: Tue, 17 Jan 2012 08:04:50 +0100 Subject: [PATCH] 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. --- lib/child_process.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 55412b94949..145a34ff4b9 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -132,7 +132,7 @@ function setupChannel(target, channel) { var writeReq = channel.write(buffer, 0, buffer.length, sendHandle); if (!writeReq) { - throw new Error(errno + 'cannot write to IPC channel.'); + throw errnoException(errno, 'write', 'cannot write to IPC channel.'); } 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 // Once all of Node is using this function the ErrnoException from // 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.syscall = syscall; return e;