Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #500 from kumar303/id-version-error
Browse files Browse the repository at this point in the history
fix: better error when id/version is empty
  • Loading branch information
kumar303 committed Feb 22, 2016
2 parents ee1447e + b1284c3 commit 1900440
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lib/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 22 additions & 3 deletions test/unit/test.sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 1900440

Please sign in to comment.