Skip to content

Commit 510c58c

Browse files
improved error handling
1 parent 986cff9 commit 510c58c

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

lib/spawnGPG.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,39 @@ module.exports.streaming = function(options, args, cb) {
9696
// Go for it
9797
var gpg = spawnIt(args, cb);
9898

99+
let stderrData = []
100+
gpg.stderr.on('data', (data) => {
101+
stderrData.push(data);
102+
});
103+
99104
if (!isDestStream) {
100105
gpg.on('close', function (code){
101-
cb(null);
106+
if (code!=0) {
107+
cb(new Error(`gpg: exit code ${code}\n${stderrData.join('')}`));
108+
} else {
109+
cb(null);
110+
}
102111
});
103112
} else {
104113
cb(null, destStream);
105114
}
106115

116+
sourceStream.on('error', function(error) {
117+
console.log(error);
118+
})
119+
120+
destStream.on('error', function(error) {
121+
console.log(error);
122+
})
123+
124+
gpg.stdin.on('error', function(error) {
125+
console.log(error);
126+
})
127+
128+
gpg.stdout.on('error', function(error) {
129+
console.log(error);
130+
})
131+
107132
// Pipe input file into gpg stdin; gpg stdout into output file..
108133
sourceStream.pipe(gpg.stdin);
109134
gpg.stdout.pipe(destStream);

0 commit comments

Comments
 (0)