Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix exit code not thrown issue when cli running into exception #1022

Merged
merged 7 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/chatdown/test/commands/chatdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('chatdown', () => {
test
.stdout()
.command(['chatdown', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Converts chat dialog files in <filename>.')
})
Expand Down
2 changes: 2 additions & 0 deletions packages/chatdown/test/commands/chatdown/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ describe('chatdown:convert', function() {
test
.stdout()
.command(['chatdown:convert', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', (ctx: any) => {
expect(ctx.stdout).to.contain('Converts chat dialog files in <filename>.')
})

test
.stdout()
.command(['chatdown'])
.exit(1)
.it('should print the help contents when no input is passed', (ctx: any) => {
expect(ctx.stdout).to.contain('Converts chat dialog files in <filename>.')
})
Expand Down
3 changes: 3 additions & 0 deletions packages/command/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export abstract class Command extends Base {
this.error(err.message)
} catch (e) {}
}

// return exit code
this.exit(1)
}

// Flush telemetry to avoid performance issues
Expand Down
16 changes: 13 additions & 3 deletions packages/command/test/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ describe('command', () => {

return Test.run([])
})
.do(output => expect(output.stderr).to.include('Unknown error during execution. Please file an issue on https://github.com/microsoft/botframework-cli/issues'))
.catch(err => {
expect(err.message).to.include('EEXIT: 1')
})
.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'))
.it('Errors out')


fancy
.stderr()
Expand All @@ -34,7 +38,10 @@ describe('command', () => {

return Test.run([])
})
.do(output => expect(output.stderr).to.equal('failure\n'))
.catch(err => {
expect(err.message).to.include('EEXIT: 1')
})
.finally(output => expect(output.stderr).to.equal('failure\n'))
.it('Exits with error')

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

return Test.run([])
})
.do(output => expect(output.stderr).to.equal('failure\n'))
.catch(err => {
expect(err.message).to.include('EEXIT: 1')
})
.finally(output => expect(output.stderr).to.equal('failure\n'))
.it('Handles OCLIF Errors')

fancy
Expand Down
1 change: 1 addition & 0 deletions packages/config/test/commands/config/set/luis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('config:set:luis', () => {
test
.stdout()
.command(['config:set:luis', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Stores default LUIS application values in global config.')
})
Expand Down
1 change: 1 addition & 0 deletions packages/config/test/commands/config/set/qnamaker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('config:set:qnamaker', () => {
test
.stdout()
.command(['config:set:qnamaker'])
.exit(1)
.it('Asks for a flag', ctx => {
expect(ctx.stdout).to.contain('Plase specify flag')
})
Expand Down
1 change: 1 addition & 0 deletions packages/config/test/commands/config/set/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('config:set:telemetry', () => {
test
.stdout()
.command(['config:set:telemetry'])
.exit(1)
.it('Shows help and keeps the same seetings', async ctx => {
let config = await fs.readJSON(getConfigFile())
expect(config.telemetry).to.be.true
Expand Down
4 changes: 4 additions & 0 deletions packages/luis/test/commands/luis/application/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('luis:application:create', () => {
test
.stdout()
.command(['luis:application:create', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Creates a new LUIS application')
})
Expand All @@ -26,6 +27,7 @@ describe('luis:application:create', () => {
.stdout()
.stderr()
.command(['luis:application:create', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1(), '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'name' missing.`)
})
Expand All @@ -34,6 +36,7 @@ describe('luis:application:create', () => {
.stdout()
.stderr()
.command(['luis:application:create', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--name', 'orange_app', '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
})
Expand All @@ -54,6 +57,7 @@ describe('luis:application:create', () => {
.stdout()
.stderr()
.command(['luis:application:create', '--endpoint', 'undefined', '--name', 'orange_app', '--subscriptionKey', uuidv1(), '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
.exit(1)
.it('fails to create an app and displays an error message if the endpoint is undefined', ctx => {
expect(ctx.stderr).to.contain('Failed to create app: TypeError: Only absolute URLs are supported\n')
})
Expand Down
4 changes: 4 additions & 0 deletions packages/luis/test/commands/luis/application/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('luis:application:delete', () => {
test
.stdout()
.command(['luis:application:delete', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Deletes a LUIS application')
})
Expand All @@ -24,6 +25,7 @@ describe('luis:application:delete', () => {
.stdout()
.stderr()
.command(['luis:application:delete', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'appId' missing.`)
})
Expand All @@ -32,6 +34,7 @@ describe('luis:application:delete', () => {
.stdout()
.stderr()
.command(['luis:application:delete', '--appId', uuidv1(), '--subscriptionKey', uuidv1()])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'endpoint' missing.`)
})
Expand All @@ -51,6 +54,7 @@ describe('luis:application:delete', () => {
.stdout()
.stderr()
.command(['luis:application:delete', '--appId', uuidv1(), '--endpoint', 'undefined', '--subscriptionKey', uuidv1(), '--force'])
.exit(1)
.it('fails to delete an app and displays an error message if the endpoint is undefined', ctx => {
expect(ctx.stderr).to.contain('Failed to delete app')
})
Expand Down
5 changes: 5 additions & 0 deletions packages/luis/test/commands/luis/application/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('luis:application:import', () => {
test
.stdout()
.command(['luis:application:import', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Imports LUIS application from JSON or LU content.')
})
Expand All @@ -25,6 +26,7 @@ describe('luis:application:import', () => {
.stdout()
.stderr()
.command(['luis:application:import', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--name', 'sample_app'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
})
Expand All @@ -45,6 +47,7 @@ describe('luis:application:import', () => {
.stdout()
.stderr()
.command(['luis:application:import', '--name', 'Sample', '--in', './test/fixtures/xyz.json', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
.exit(1)
.it('displays an error message if the import file cannot be found', ctx => {
expect(ctx.stderr).to.contain('Failed to read app JSON')
})
Expand All @@ -53,6 +56,7 @@ describe('luis:application:import', () => {
.stdout()
.stderr()
.command(['luis:application:import', '--name', 'Sample', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
.exit(1)
.it('displays an error message if no input data detected', ctx => {
expect(ctx.stderr).to.contain('No import data found - please provide input through stdin or the --in flag')
})
Expand All @@ -62,6 +66,7 @@ describe('luis:application:import', () => {
.stdout()
.stderr()
.command(['luis:application:import', '--name', 'sampleapp', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
.exit(1)
.it('imports a luis app from stdin and returns the app\'s id', ctx => {
process.stdin.setEncoding('utf8')
process.stdin.once('data', data => {
Expand Down
3 changes: 3 additions & 0 deletions packages/luis/test/commands/luis/application/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('luis:application:list', () => {
test
.stdout()
.command(['luis:application:list', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Lists all applications on LUIS service.')
})
Expand All @@ -37,6 +38,7 @@ describe('luis:application:list', () => {
.stdout()
.stderr()
.command(['luis:application:list', '--endpoint', 'https://westus.api.cognitive.microsoft.com'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
})
Expand Down Expand Up @@ -72,6 +74,7 @@ describe('luis:application:list', () => {
.stdout()
.stderr()
.command(['luis:application:list', '--out', 'xyz', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com'])
.exit(1)
.it('displays a list of applications and a success message in the console (since the target path provided is invalid)', ctx => {
expect(ctx.stderr).to.contain('Target directory path doesn\'t exist:')
})
Expand Down
3 changes: 3 additions & 0 deletions packages/luis/test/commands/luis/application/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('luis:application:publish', () => {
test
.stdout()
.command(['luis:application:publish', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Publishes application\'s version')
})
Expand All @@ -28,6 +29,7 @@ describe('luis:application:publish', () => {
.stdout()
.stderr()
.command(['luis:application:publish', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1(), '--appId', uuidv1()])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'versionId' missing.`)
})
Expand All @@ -36,6 +38,7 @@ describe('luis:application:publish', () => {
.stdout()
.stderr()
.command(['luis:application:publish', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--versionId', '0.01'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
})
Expand Down
4 changes: 4 additions & 0 deletions packages/luis/test/commands/luis/application/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('luis:application:query', () => {
test
.stdout()
.command(['luis:application:query', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Queries application for intent predictions')
})
Expand All @@ -28,6 +29,7 @@ describe('luis:application:query', () => {
.stdout()
.stderr()
.command(['luis:application:query', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--staging', '--subscriptionKey', uuidv1()])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'query' missing.`)
})
Expand All @@ -36,6 +38,7 @@ describe('luis:application:query', () => {
.stdout()
.stderr()
.command(['luis:application:query', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1(), '--staging', '--query', 'test query'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'appId' missing.`)
})
Expand All @@ -62,6 +65,7 @@ describe('luis:application:query', () => {
.stdout()
.stderr()
.command(['luis:application:query', '--endpoint', 'undefined', '--appId', uuidv1(), '--subscriptionKey', uuidv1(), '--staging', '--query', 'test query'])
.exit(1)
.it('fails to query app and displays an error message if the endpoint is null', ctx => {
expect(ctx.stderr).to.contain('Failed to fetch prediction data')
})
Expand Down
4 changes: 4 additions & 0 deletions packages/luis/test/commands/luis/application/rename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('luis:application:rename', () => {
test
.stdout()
.command(['luis:application:rename', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Renames the application and updates its description')
})
Expand All @@ -28,6 +29,7 @@ describe('luis:application:rename', () => {
.stdout()
.stderr()
.command(['luis:application:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--subscriptionKey', uuidv1(), '--description', 'test description'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain('Missing required flag:')
expect(ctx.stderr).to.contain('--name NAME')
Expand All @@ -37,6 +39,7 @@ describe('luis:application:rename', () => {
.stdout()
.stderr()
.command(['luis:application:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--name', 'sample-app', '--description', 'test description'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
})
Expand All @@ -57,6 +60,7 @@ describe('luis:application:rename', () => {
.stdout()
.stderr()
.command(['luis:application:rename', '--endpoint', 'undefined', '--subscriptionKey', uuidv1(), '--appId', uuidv1(), '--name', 'sample-app', '--description', 'test description'])
.exit(1)
.it('fails to create an app and displays an error message if the endpoint is undefined', ctx => {
expect(ctx.stderr).to.contain('Failed to rename app: TypeError: Only absolute URLs are supported\n')
})
Expand Down
2 changes: 2 additions & 0 deletions packages/luis/test/commands/luis/application/show.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('luis:application:show', () => {
test
.stdout()
.command(['luis:application:show', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Shows application information')
})
Expand All @@ -25,6 +26,7 @@ describe('luis:application:show', () => {
.stdout()
.stderr()
.command(['luis:application:show', '--endpoint', 'https://westus.api.cognitive.microsoft.com'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
})
Expand Down
7 changes: 7 additions & 0 deletions packages/luis/test/commands/luis/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('luis:build cli parameters test', () => {
test
.stdout()
.command(['luis:build', '--help'])
.exit(1)
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Build lu files to train and publish luis applications')
})
Expand All @@ -28,6 +29,7 @@ describe('luis:build cli parameters test', () => {
.stdout()
.stderr()
.command(['luis:build', '--in', `${path.join(__dirname, './../../fixtures/testcases/lubuild')}`, '--botName', 'Contoso'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain('Missing LUIS authoring key. Please pass authoring key with --authoringKey flag')
})
Expand All @@ -36,6 +38,7 @@ describe('luis:build cli parameters test', () => {
.stdout()
.stderr()
.command(['luis:build', '--authoringKey', uuidv1(), '--botName', 'Contoso'])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain('Missing input. Please use stdin or pass a file or folder location with --in flag')
})
Expand All @@ -44,6 +47,7 @@ describe('luis:build cli parameters test', () => {
.stdout()
.stderr()
.command(['luis:build', '--authoringKey', uuidv1(), '--in', `${path.join(__dirname, './../../fixtures/testcases/lubuild')}`])
.exit(1)
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain('Missing bot name. Please pass bot name with --botName flag')
})
Expand All @@ -52,6 +56,7 @@ describe('luis:build cli parameters test', () => {
.stdout()
.stderr()
.command(['luis:build', '--authoringKey', uuidv1(), '--in', `${path.join(__dirname, './../../fixtures/testcases/lubuild/file-name-duplicated')}`, '--botName', 'Contoso'])
.exit(1)
.it('displays an error if files with same name and locale are found', ctx => {
expect(ctx.stderr).to.contain('Files with same name and locale are found')
})
Expand All @@ -60,6 +65,7 @@ describe('luis:build cli parameters test', () => {
.stdout()
.stderr()
.command(['luis:build', '--authoringKey', uuidv1(), '--in', `${path.join(__dirname, './../../fixtures/testcases/invalid_import_file.lu')}`, '--botName', 'Contoso'])
.exit(1)
.it('displays an error if error occurs in parsing lu content', ctx => {
expect(ctx.stderr).to.contain('Invalid LU file')
expect(ctx.stderr).to.contain('bad3.lu')
Expand All @@ -70,6 +76,7 @@ describe('luis:build cli parameters test', () => {
.stdout()
.stderr()
.command(['luis:build', '--authoringKey', uuidv1(), '--in', `${path.join(__dirname, './../../fixtures/testcases/lubuild')}`, '--botName', 'Contoso', '--dialog', 'cross-train'])
.exit(1)
.it('displays an error if option specified by --dialog is not right', ctx => {
expect(ctx.stderr).to.contain('Recognizer type specified by --dialog is not right. Please specify [multiLanguage|crosstrained]')
})
Expand Down