From: Ryan Dahl Date: Fri, 28 Jan 2011 01:45:17 +0000 (-0800) Subject: Helpful error when child_process.exec hit maxBuffer X-Git-Tag: v0.3.7~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb06abe1e586217e31907d792ef3b967936e3f77;p=platform%2Fupstream%2Fnodejs.git Helpful error when child_process.exec hit maxBuffer --- diff --git a/lib/child_process.js b/lib/child_process.js index 71792f7..fd4a314 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -60,6 +60,8 @@ exports.execFile = function(file /* args, options, callback */) { var exited = false; var timeoutId; + var err; + function exithandler(code, signal) { if (exited) return; exited = true; @@ -71,7 +73,9 @@ exports.execFile = function(file /* args, options, callback */) { if (!callback) return; - if (code === 0 && signal === null) { + if (err) { + callback(err, stdout, stderr); + } else if (code === 0 && signal === null) { callback(null, stdout, stderr); } else { var e = new Error('Command failed: ' + stderr); @@ -103,6 +107,7 @@ exports.execFile = function(file /* args, options, callback */) { child.stdout.addListener('data', function(chunk) { stdout += chunk; if (stdout.length > options.maxBuffer) { + err = new Error('maxBuffer exceeded.'); kill(); } }); @@ -110,6 +115,7 @@ exports.execFile = function(file /* args, options, callback */) { child.stderr.addListener('data', function(chunk) { stderr += chunk; if (stderr.length > options.maxBuffer) { + err = new Error('maxBuffer exceeded.'); kill(); } }); diff --git a/test/simple/test-exec-max-buffer.js b/test/simple/test-exec-max-buffer.js new file mode 100644 index 0000000..a5a24ea --- /dev/null +++ b/test/simple/test-exec-max-buffer.js @@ -0,0 +1,10 @@ +var common = require('../common'); +var exec = require('child_process').exec; +var assert = require('assert'); + +var cmd = 'echo "hello world"'; + +exec(cmd, { maxBuffer: 5 }, function(err, stdout, stderr) { + assert.ok(err); + assert.ok(/maxBuffer/.test(err.message)); +});