Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: try to make error messages more informative #39

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Log = require('./logger');
const _shell = require('shelljs');
const path = require('path');
const parse = require('yargs-parser');
const os = require('os');
const Promise = require('./promise');
const stdoutStream = require('through');
const stderrStream = require('through');
Expand Down Expand Up @@ -149,13 +148,16 @@ module.exports = class Shell {
// Assess the results
.then(({code, stdout, stderr}) => {
// if this is an error and stderr is empty use the last few lines of STDOUT
if (code !== 0 && _.isEmpty(stderr)) stderr = _.trim(_.last(_.compact(stdout.split(os.EOL))));
if (code !== 0 && _.isEmpty(stderr)) {
stderr = stdout.trim();
}
// Log
this.log.debug('process %s finished with exit code %s', id, code);
this.log.silly('process %s had output', id, {stdout, stderr});
// Return
_.remove(this.running, proc => proc.id === id);
return (code !== 0) ? Promise.reject(new Error(stderr)) : Promise.resolve(stdout);
const msg = `${cmd} failed with exit code ${code}\n:${stderr}`;
return (code !== 0) ? Promise.reject(new Error(msg)) : Promise.resolve(stdout);
});
};

Expand Down
Loading