Skip to content

Commit fab52aa

Browse files
Sindhura3schamala
and
schamala
authored
fix exit code regression (twilio#199)
Co-authored-by: schamala <[email protected]>
1 parent 632994b commit fab52aa

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

src/base-commands/base-command.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ class BaseCommand extends Command {
7373
this.logger.error(error.message);
7474
this.logger.debug(error.stack);
7575
}
76-
this.exit(error.exitCode || 1);
76+
let code = 1;
77+
if (error.exitCode) {
78+
code = parseInt(error.exitCode.toString().substring(0, 2), 10);
79+
}
80+
this.exit(code);
7781
} else {
7882
// System errors
7983
let url = '';

src/services/cli-http-client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class CliRequestClient {
159159
const moreInfoMessage = more_info ? `See ${more_info} for more info.` : '';
160160
const error = {
161161
message: `Error code ${code || 'N/A'} from Twilio: ${message || 'No message provided'}. ${moreInfoMessage}`,
162-
code: code.toString().substring(0, 2),
162+
code,
163163
details,
164164
};
165165

test/base-commands/base-command.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ describe('base-commands', () => {
5959
expect(ctx.stderr).to.contain('oy!');
6060
});
6161

62+
test
63+
.twilioCliEnv()
64+
.stdout()
65+
.do(async (ctx) => {
66+
ctx.testCmd = new BaseCommand(['-o', 'json'], ctx.fakeConfig);
67+
await ctx.testCmd.run();
68+
await ctx.testCmd.catch(new TwilioCliError('oh no', 2003, { errors: [{ message: 'oh no' }] }));
69+
})
70+
.exit(20)
71+
.it('can correctly cut exit code', (ctx) => {
72+
expect(ctx.stdout).to.contain(`"message": "oh no"`);
73+
});
74+
6275
test
6376
.twilioCliEnv()
6477
.stdout()

test/base-commands/twilio-client-command.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ describe('base-commands', () => {
184184
});
185185

186186
setUpTest([], { commandClass: Throwing20003ClientCommand })
187-
.exit(20003)
187+
.exit(20)
188188
.it('should catch access denied errors and enhance the message', (ctx) => {
189189
expect(ctx.stderr).to.contain('Access Denied');
190190
expect(ctx.stderr).to.contain('Standard API Keys');
191191
});
192192

193193
setUpTest([], { commandClass: Throwing20003ClientCommand, envRegion: 'region' })
194-
.exit(20003)
194+
.exit(20)
195195
.it('should catch access denied errors but not enhance the message when using env var auth', (ctx) => {
196196
expect(ctx.stderr).to.contain('Access Denied');
197197
expect(ctx.stderr).to.not.contain('Standard API Keys');

test/services/cli-http-client.test.js

-12
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,5 @@ describe('services', () => {
125125
});
126126
expect(response.statusCode).to.equal(200);
127127
});
128-
129-
test.it('correct exit code', () => {
130-
const client = new CliRequestClient('bleh', logger);
131-
const response = {
132-
code: 20404,
133-
message: 'error',
134-
moreInfo: '',
135-
details: '',
136-
};
137-
const { message, code } = client.formatErrorMessage(response);
138-
expect(code).to.equal('20');
139-
});
140128
});
141129
});

0 commit comments

Comments
 (0)