Skip to content

Commit

Permalink
Merge pull request #28 from Janus-vistaprint/fixErrorPipe
Browse files Browse the repository at this point in the history
emit errors to stream #27
  • Loading branch information
TerribleDev authored Feb 8, 2018
2 parents 8c7ce97 + e6d93eb commit e232ec6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/declarations/child-process-promise.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
declare module "child-process-promise";
declare module "child-process-promise" {
export function spawn(command: string, arguments: string[], options: any): Promise<any>;
}
11 changes: 9 additions & 2 deletions src/shelly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function shelly(command: string, noun: string|string[], args: any
throw new PluginError(PLUGIN_NAME, "Arguments has to be an array");
}
// Creating a stream through which each file will pass
return through.obj((file, enc, cb) => {
return through.obj(function(this: Transform, file, enc, cb) {
if (!file || !file.path) {
// return empty file
return cb(null, file);
Expand All @@ -45,7 +45,14 @@ export default function shelly(command: string, noun: string|string[], args: any
}
cp.spawn(command, calculatedArgs, options)
.then((a: any) => cb(null, file))
.catch((ex: any) => cb(ex, file));
.catch((ex: Error) => {
let pluginError = new PluginError(PLUGIN_NAME, `failed to ${noun}`);
this.emit("error", pluginError);
cb(pluginError, file);
})
// emit will trick node in thinking we have unhandled promise rejections
// tslint:disable-next-line:no-empty
.catch((ex) => { });

});

Expand Down

0 comments on commit e232ec6

Please sign in to comment.