Skip to content

Commit

Permalink
fix: throw proper error on failing gradle execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Drukh committed Sep 8, 2018
1 parent f77b7bf commit 77f0e32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
19 changes: 13 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function inspect(root, targetFile, options) {
if (!options) {
options = {dev: false};
}
return getPackage(root, targetFile, options)
var command = getCommand(root, targetFile);
var args = buildArgs(root, targetFile, options.args);
return getPackage(root, command, args)
.then(function (pkg) {
// opt-in with `jars` or `localjars` flag
if (options.jars || options.localjars) {
Expand All @@ -40,14 +42,19 @@ function inspect(root, targetFile, options) {
},
package: pkg,
};
})
.catch(function (error) {
error.message = error.message + '\n\n' +
'Please make sure that `' + command + ' ' + args.join(' ') +
'` executes successfully on this project.\n\n' +
'If the problem persists, collect the output of `' +
command + ' ' + args.join(' ') + '` and contact [email protected]\n';
throw error;
});
}

function getPackage(root, targetFile, options) {
return subProcess.execute(
getCommand(root, targetFile),
buildArgs(root, targetFile, options.args),
{cwd: root})
function getPackage(root, command, args) {
return subProcess.execute(command, args, {cwd: root})
.then(function (result) {
var packageName = path.basename(root);
var packageVersion = '0.0.0';
Expand Down
2 changes: 1 addition & 1 deletion lib/sub-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports.execute = function (command, args, options) {

proc.on('close', function (code) {
if (code !== 0) {
return reject(stdout || stderr);
return reject(new Error(stdout || stderr));
}
resolve(stdout || stderr);
});
Expand Down
16 changes: 15 additions & 1 deletion test/system/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ test('run inspect()', function (t) {
.catch(t.fail);
});

test('failing inspect()', function (t) {
t.plan(1);
stubSubProcessExec(t);
return plugin.inspect('.', path.join(
__dirname, '..', 'fixtures', 'no-wrapper', 'build.gradle'))
.then(function (result) {
t.fail('Should have thrown!', result);
})
.catch(function (error) {
t.match(error.message, 'executes successfully on this project',
'proper error message');
});
});

test('windows without wrapper', function (t) {
t.plan(1);

Expand Down Expand Up @@ -134,7 +148,7 @@ function stubPlatform(platform, t) {
function stubSubProcessExec(t) {
sinon.stub(subProcess, 'execute')
.callsFake(function () {
return Promise.reject('abort');
return Promise.reject(new Error('abort'));
});
t.teardown(subProcess.execute.restore);
}

0 comments on commit 77f0e32

Please sign in to comment.