From b1284c38eb90752ae1c05589b2c219bff6809bc6 Mon Sep 17 00:00:00 2001 From: Kumar McMillan Date: Mon, 22 Feb 2016 11:50:36 -0600 Subject: [PATCH] fix: better error when id/version is empty --- lib/sign.js | 11 ++++++++++- test/unit/test.sign.js | 25 ++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/sign.js b/lib/sign.js index 42afee2..37d0ed5 100644 --- a/lib/sign.js +++ b/lib/sign.js @@ -100,6 +100,15 @@ function sign(options, config) { } }).then(function(xpiInfo) { + if (!xpiInfo.id || !xpiInfo.version) { + throw new Error( + "Could not detect this XPI's ID and/or version\n\n" + + "Troubleshooting:\n" + + "- Are you in the right directory? If not, try --addon-dir\n" + + "- Are you really in a directory of SDK add-on source? If not, try " + + "signing with the --xpi option\n"); + } + var client = new config.AMOClient({ apiKey: options.apiKey, apiSecret: options.apiSecret, @@ -134,7 +143,7 @@ function signCmd(program, options, config) { }).then(function(result) { logger.log(result.success ? "SUCCESS" : "FAIL"); config.systemProcess.exit(result.success ? 0 : 1); - }, function(err) { + }).catch(function(err) { logger.error("FAIL"); if (err) { console.error(err.stack); diff --git a/test/unit/test.sign.js b/test/unit/test.sign.js index 4d2f6fd..80f0f00 100644 --- a/test/unit/test.sign.js +++ b/test/unit/test.sign.js @@ -985,8 +985,8 @@ describe("sign", function() { createXPI: mockXPICreator.getCallable(), program: { verbose: true, - addonDir: "", - } + addonDir: simpleAddonPath, + }, }).then(function() { expect(fakeClientContructor.call[0].debugLogging).to.be.equal(true); done(); @@ -1010,7 +1010,10 @@ describe("sign", function() { it("passes custom XPI to the signer", function(done) { var mockXpiInfoGetter = new CallableMock({ returnValue: when.promise(function(resolve) { - resolve({}); // resolve with empty xpiInfo. + resolve({ + id: 'some-id', + version: '0.0.1', + }); }), }); // Make sure nothing is checking the working directory for add-on @@ -1045,6 +1048,22 @@ describe("sign", function() { }).catch(done); }); + it("exits 1 when id/version cannot be detected", function(done) { + var mockXpiInfoGetter = new CallableMock({ + returnValue: when.promise(function(resolve) { + // Resolve an empty XPI info object which will happen + // in various scenarios when id/version cannot be detected. + resolve({}); + }), + }); + runSignCmd({ + getXpiInfoForSigning: mockXpiInfoGetter.getCallable(), + }).then(function() { + expect(mockProcessExit.call[0]).to.be.equal(1); + done(); + }).catch(done); + }); + it("should exit 1 on exception", function(done) { runSignCmd({ StubAMOClient: makeAMOClientStub({