Permalink
Browse files

recover from a decoding exception

  • Loading branch information...
1 parent ce9826a commit 65e98673b8cb5f402e0c8f14cdab948f21b0f729 @mykmelez committed Sep 28, 2012
Showing with 26 additions and 6 deletions.
  1. +26 −6 lib/subprocess.js
View
@@ -351,6 +351,12 @@ function setTimeout(callback, timeout) {
timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_ONE_SHOT);
};
+function getBytes(data) {
+ var string = '';
+ data.forEach(function(x) { string += String.fromCharCode(x < 0 ? x + 256 : x) });
+ return string;
+}
+
function readString(data, length, charset) {
var string = '', bytes = [];
for(var i = 0;i < length; i++) {
@@ -920,10 +926,17 @@ function subprocess_win32(options) {
debugLog("got "+event.data.count+" bytes from "+name+"\n");
var data = '';
if (options.charset === null) {
- event.data.data.forEach(function(x) { data += String.fromCharCode(x < 0 ? x + 256 : x) })
+ data = getBytes(event.data.data);
+ }
+ else {
+ try {
+ data = convertBytes(event.data.data, options.charset);
+ }
+ catch(ex) {
+ console.warn("error decoding output: " + ex);
+ data = getBytes(event.data.data);
+ }
}
- else
- data = convertBytes(event.data.data, options.charset);
callbackFunc(data);
break;
@@ -1451,10 +1464,17 @@ function subprocess_unix(options) {
debugLog("got "+event.data.count+" bytes from "+name+"\n");
var data = '';
if (options.charset === null) {
- event.data.data.forEach(function(x) { data += String.fromCharCode(x < 0 ? x + 256 : x) })
+ data = getBytes(event.data.data);
+ }
+ else {
+ try {
+ data = convertBytes(event.data.data, options.charset);
+ }
+ catch(ex) {
+ console.warn("error decoding output: " + ex);
+ data = getBytes(event.data.data);
+ }
}
- else
- data = convertBytes(event.data.data, options.charset);
callbackFunc(data);
break;

0 comments on commit 65e9867

Please sign in to comment.