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

refactor(check_reqs): drop originalError param from check_android_target #1260

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions bin/templates/cordova/lib/builders/ProjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,23 @@ class ProjectBuilder {
* Builds the project with gradle.
* Returns a promise.
*/
build (opts) {
async build (opts) {
var wrapper = path.join(this.root, 'gradlew');
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);

return execa(wrapper, args, { stdio: 'inherit', cwd: path.resolve(this.root) })
.catch(function (error) {
if (error.toString().indexOf('failed to find target with hash string') >= 0) {
return check_reqs.check_android_target(error).then(function () {
// If due to some odd reason - check_android_target succeeds
// we should still fail here.
throw error;
});
try {
return await execa(wrapper, args, { stdio: 'inherit', cwd: path.resolve(this.root) });
} catch (error) {
if (error.toString().includes('failed to find target with hash string')) {
// Add hint from check_android_target to error message
try {
await check_reqs.check_android_target();
} catch (checkAndroidTargetError) {
error.message += '\n' + checkAndroidTargetError.message;
}
throw error;
});
}
throw error;
}
}

clean (opts) {
Expand Down
8 changes: 2 additions & 6 deletions bin/templates/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ module.exports.check_android = function () {
});
};

module.exports.check_android_target = function (originalError) {
module.exports.check_android_target = function () {
// valid_target can look like:
// android-19
// android-L
Expand All @@ -257,11 +257,7 @@ module.exports.check_android_target = function (originalError) {
if (targets.indexOf(desired_api_level) >= 0) {
return targets;
}
var msg = `Please install the Android SDK Platform "platforms;${desired_api_level}"`;
if (originalError) {
msg = originalError + '\n' + msg;
}
throw new CordovaError(msg);
throw new CordovaError(`Please install the Android SDK Platform "platforms;${desired_api_level}"`);
});
};

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/builders/ProjectBuilder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('ProjectBuilder', () => {
return builder.build({}).then(
() => fail('Unexpectedly resolved'),
error => {
expect(checkReqsSpy.check_android_target).toHaveBeenCalledWith(testError);
expect(checkReqsSpy.check_android_target).toHaveBeenCalled();
expect(error).toBe(testError);
}
);
Expand Down