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

This commit is contained in:
Raphael von der Grün 2021-07-06 13:33:26 +02:00 committed by GitHub
parent 334d02d26e
commit 6f35d0b2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 18 deletions

View File

@ -300,21 +300,23 @@ class ProjectBuilder {
* Builds the project with gradle. * Builds the project with gradle.
* Returns a promise. * Returns a promise.
*/ */
build (opts) { async build (opts) {
var wrapper = path.join(this.root, 'gradlew'); var wrapper = path.join(this.root, 'gradlew');
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts); var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
return execa(wrapper, args, { stdio: 'inherit', cwd: path.resolve(this.root) }) try {
.catch(function (error) { return await execa(wrapper, args, { stdio: 'inherit', cwd: path.resolve(this.root) });
if (error.toString().indexOf('failed to find target with hash string') >= 0) { } catch (error) {
return check_reqs.check_android_target(error).then(function () { if (error.toString().includes('failed to find target with hash string')) {
// If due to some odd reason - check_android_target succeeds // Add hint from check_android_target to error message
// we should still fail here. try {
throw error; await check_reqs.check_android_target();
}); } catch (checkAndroidTargetError) {
error.message += '\n' + checkAndroidTargetError.message;
}
} }
throw error; throw error;
}); }
} }
clean (opts) { clean (opts) {

View File

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

View File

@ -224,7 +224,7 @@ describe('ProjectBuilder', () => {
return builder.build({}).then( return builder.build({}).then(
() => fail('Unexpectedly resolved'), () => fail('Unexpectedly resolved'),
error => { error => {
expect(checkReqsSpy.check_android_target).toHaveBeenCalledWith(testError); expect(checkReqsSpy.check_android_target).toHaveBeenCalled();
expect(error).toBe(testError); expect(error).toBe(testError);
} }
); );