You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2021/07/06 11:33:32 UTC

[cordova-android] branch master updated: refactor(check_reqs): drop originalError param from check_android_target (#1260)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git


The following commit(s) were added to refs/heads/master by this push:
     new 6f35d0b  refactor(check_reqs): drop originalError param from check_android_target (#1260)
6f35d0b is described below

commit 6f35d0b2b70d3d1605a4ce911f8fe543b22c6ccd
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Tue Jul 6 13:33:26 2021 +0200

    refactor(check_reqs): drop originalError param from check_android_target (#1260)
---
 .../cordova/lib/builders/ProjectBuilder.js         | 24 ++++++++++++----------
 bin/templates/cordova/lib/check_reqs.js            |  8 ++------
 spec/unit/builders/ProjectBuilder.spec.js          |  2 +-
 3 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/bin/templates/cordova/lib/builders/ProjectBuilder.js b/bin/templates/cordova/lib/builders/ProjectBuilder.js
index 129a01b..08e21da 100644
--- a/bin/templates/cordova/lib/builders/ProjectBuilder.js
+++ b/bin/templates/cordova/lib/builders/ProjectBuilder.js
@@ -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) {
diff --git a/bin/templates/cordova/lib/check_reqs.js b/bin/templates/cordova/lib/check_reqs.js
index 3a9ee16..86f9890 100644
--- a/bin/templates/cordova/lib/check_reqs.js
+++ b/bin/templates/cordova/lib/check_reqs.js
@@ -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
@@ -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}"`);
     });
 };
 
diff --git a/spec/unit/builders/ProjectBuilder.spec.js b/spec/unit/builders/ProjectBuilder.spec.js
index 5ea7b23..8cd653d 100644
--- a/spec/unit/builders/ProjectBuilder.spec.js
+++ b/spec/unit/builders/ProjectBuilder.spec.js
@@ -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);
                 }
             );

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org