Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 091464d

Browse files
authored
fix exit code not thrown issue when cli running into exception (#1022)
* add exit code for command when running into exception * fix test * adjust test * fix test case * fix test * remove unused code
1 parent 24ec3b9 commit 091464d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+134
-4
lines changed

packages/chatdown/test/commands/chatdown.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ describe('chatdown', () => {
55
test
66
.stdout()
77
.command(['chatdown', '--help'])
8+
.exit(1)
89
.it('should print the help contents when --help is passed as an argument', ctx => {
910
expect(ctx.stdout).to.contain('Converts chat dialog files in <filename>.')
1011
})

packages/chatdown/test/commands/chatdown/convert.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ describe('chatdown:convert', function() {
2121
test
2222
.stdout()
2323
.command(['chatdown:convert', '--help'])
24+
.exit(1)
2425
.it('should print the help contents when --help is passed as an argument', (ctx: any) => {
2526
expect(ctx.stdout).to.contain('Converts chat dialog files in <filename>.')
2627
})
2728

2829
test
2930
.stdout()
3031
.command(['chatdown'])
32+
.exit(1)
3133
.it('should print the help contents when no input is passed', (ctx: any) => {
3234
expect(ctx.stdout).to.contain('Converts chat dialog files in <filename>.')
3335
})

packages/command/src/command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export abstract class Command extends Base {
5050
this.error(err.message)
5151
} catch (e) {}
5252
}
53+
54+
// return exit code
55+
this.exit(1)
5356
}
5457

5558
// Flush telemetry to avoid performance issues

packages/command/test/command.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ describe('command', () => {
1919

2020
return Test.run([])
2121
})
22-
.do(output => expect(output.stderr).to.include('Unknown error during execution. Please file an issue on https://github.com/microsoft/botframework-cli/issues'))
22+
.catch(err => {
23+
expect(err.message).to.include('EEXIT: 1')
24+
})
25+
.finally(output => expect(output.stderr).to.equal('Unknown error during execution. Please file an issue on https://github.com/microsoft/botframework-cli/issues\nfailure\n'))
2326
.it('Errors out')
27+
2428

2529
fancy
2630
.stderr()
@@ -34,7 +38,10 @@ describe('command', () => {
3438

3539
return Test.run([])
3640
})
37-
.do(output => expect(output.stderr).to.equal('failure\n'))
41+
.catch(err => {
42+
expect(err.message).to.include('EEXIT: 1')
43+
})
44+
.finally(output => expect(output.stderr).to.equal('failure\n'))
3845
.it('Exits with error')
3946

4047
fancy
@@ -48,7 +55,10 @@ describe('command', () => {
4855

4956
return Test.run([])
5057
})
51-
.do(output => expect(output.stderr).to.equal('failure\n'))
58+
.catch(err => {
59+
expect(err.message).to.include('EEXIT: 1')
60+
})
61+
.finally(output => expect(output.stderr).to.equal('failure\n'))
5262
.it('Handles OCLIF Errors')
5363

5464
fancy

packages/config/test/commands/config/set/luis.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('config:set:luis', () => {
1414
test
1515
.stdout()
1616
.command(['config:set:luis', '--help'])
17+
.exit(1)
1718
.it('should print the help contents when --help is passed as an argument', ctx => {
1819
expect(ctx.stdout).to.contain('Stores default LUIS application values in global config.')
1920
})

packages/config/test/commands/config/set/qnamaker.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('config:set:qnamaker', () => {
4646
test
4747
.stdout()
4848
.command(['config:set:qnamaker'])
49+
.exit(1)
4950
.it('Asks for a flag', ctx => {
5051
expect(ctx.stdout).to.contain('Plase specify flag')
5152
})

packages/config/test/commands/config/set/telemetry.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('config:set:telemetry', () => {
2323
test
2424
.stdout()
2525
.command(['config:set:telemetry'])
26+
.exit(1)
2627
.it('Shows help and keeps the same seetings', async ctx => {
2728
let config = await fs.readJSON(getConfigFile())
2829
expect(config.telemetry).to.be.true

packages/luis/test/commands/luis/application/create.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('luis:application:create', () => {
1818
test
1919
.stdout()
2020
.command(['luis:application:create', '--help'])
21+
.exit(1)
2122
.it('should print the help contents when --help is passed as an argument', ctx => {
2223
expect(ctx.stdout).to.contain('Creates a new LUIS application')
2324
})
@@ -26,6 +27,7 @@ describe('luis:application:create', () => {
2627
.stdout()
2728
.stderr()
2829
.command(['luis:application:create', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1(), '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
30+
.exit(1)
2931
.it('displays an error if any required input parameters are missing', ctx => {
3032
expect(ctx.stderr).to.contain(`Required input property 'name' missing.`)
3133
})
@@ -34,6 +36,7 @@ describe('luis:application:create', () => {
3436
.stdout()
3537
.stderr()
3638
.command(['luis:application:create', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--name', 'orange_app', '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
39+
.exit(1)
3740
.it('displays an error if any required input parameters are missing', ctx => {
3841
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
3942
})
@@ -54,6 +57,7 @@ describe('luis:application:create', () => {
5457
.stdout()
5558
.stderr()
5659
.command(['luis:application:create', '--endpoint', 'undefined', '--name', 'orange_app', '--subscriptionKey', uuidv1(), '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
60+
.exit(1)
5761
.it('fails to create an app and displays an error message if the endpoint is undefined', ctx => {
5862
expect(ctx.stderr).to.contain('Failed to create app: TypeError: Only absolute URLs are supported\n')
5963
})

packages/luis/test/commands/luis/application/delete.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('luis:application:delete', () => {
1616
test
1717
.stdout()
1818
.command(['luis:application:delete', '--help'])
19+
.exit(1)
1920
.it('should print the help contents when --help is passed as an argument', ctx => {
2021
expect(ctx.stdout).to.contain('Deletes a LUIS application')
2122
})
@@ -24,6 +25,7 @@ describe('luis:application:delete', () => {
2425
.stdout()
2526
.stderr()
2627
.command(['luis:application:delete', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
28+
.exit(1)
2729
.it('displays an error if any required input parameters are missing', ctx => {
2830
expect(ctx.stderr).to.contain(`Required input property 'appId' missing.`)
2931
})
@@ -32,6 +34,7 @@ describe('luis:application:delete', () => {
3234
.stdout()
3335
.stderr()
3436
.command(['luis:application:delete', '--appId', uuidv1(), '--subscriptionKey', uuidv1()])
37+
.exit(1)
3538
.it('displays an error if any required input parameters are missing', ctx => {
3639
expect(ctx.stderr).to.contain(`Required input property 'endpoint' missing.`)
3740
})
@@ -51,6 +54,7 @@ describe('luis:application:delete', () => {
5154
.stdout()
5255
.stderr()
5356
.command(['luis:application:delete', '--appId', uuidv1(), '--endpoint', 'undefined', '--subscriptionKey', uuidv1(), '--force'])
57+
.exit(1)
5458
.it('fails to delete an app and displays an error message if the endpoint is undefined', ctx => {
5559
expect(ctx.stderr).to.contain('Failed to delete app')
5660
})

packages/luis/test/commands/luis/application/import.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('luis:application:import', () => {
1717
test
1818
.stdout()
1919
.command(['luis:application:import', '--help'])
20+
.exit(1)
2021
.it('should print the help contents when --help is passed as an argument', ctx => {
2122
expect(ctx.stdout).to.contain('Imports LUIS application from JSON or LU content.')
2223
})
@@ -25,6 +26,7 @@ describe('luis:application:import', () => {
2526
.stdout()
2627
.stderr()
2728
.command(['luis:application:import', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--name', 'sample_app'])
29+
.exit(1)
2830
.it('displays an error if any required input parameters are missing', ctx => {
2931
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
3032
})
@@ -45,6 +47,7 @@ describe('luis:application:import', () => {
4547
.stdout()
4648
.stderr()
4749
.command(['luis:application:import', '--name', 'Sample', '--in', './test/fixtures/xyz.json', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
50+
.exit(1)
4851
.it('displays an error message if the import file cannot be found', ctx => {
4952
expect(ctx.stderr).to.contain('Failed to read app JSON')
5053
})
@@ -53,6 +56,7 @@ describe('luis:application:import', () => {
5356
.stdout()
5457
.stderr()
5558
.command(['luis:application:import', '--name', 'Sample', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
59+
.exit(1)
5660
.it('displays an error message if no input data detected', ctx => {
5761
expect(ctx.stderr).to.contain('No import data found - please provide input through stdin or the --in flag')
5862
})
@@ -62,6 +66,7 @@ describe('luis:application:import', () => {
6266
.stdout()
6367
.stderr()
6468
.command(['luis:application:import', '--name', 'sampleapp', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
69+
.exit(1)
6570
.it('imports a luis app from stdin and returns the app\'s id', ctx => {
6671
process.stdin.setEncoding('utf8')
6772
process.stdin.once('data', data => {

0 commit comments

Comments
 (0)