Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit b87052c

Browse files
committed
fix: rethrow cli-ux errors
1 parent d991efd commit b87052c

File tree

5 files changed

+112
-95
lines changed

5 files changed

+112
-95
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"supports-color": "^5.1.0"
2323
},
2424
"devDependencies": {
25-
"@anycli/tslint": "^0.1.3",
26-
"@commitlint/cli": "^6.0.2",
27-
"@commitlint/config-conventional": "^6.0.2",
25+
"@anycli/tslint": "^0.2.0",
26+
"@commitlint/cli": "^6.0.5",
27+
"@commitlint/config-conventional": "^6.0.4",
2828
"@types/ansi-styles": "^2.0.30",
2929
"@types/chai": "^4.1.2",
3030
"@types/clean-stack": "^1.3.0",
@@ -37,20 +37,20 @@
3737
"@types/node": "^9.4.0",
3838
"@types/node-notifier": "^0.0.28",
3939
"@types/read-pkg": "^3.0.0",
40-
"@types/semver": "^5.4.0",
40+
"@types/semver": "^5.5.0",
4141
"@types/strip-ansi": "^3.0.0",
4242
"@types/supports-color": "^3.1.0",
4343
"chai": "^4.1.2",
4444
"eslint": "^4.16.0",
45-
"eslint-config-anycli": "^1.2.1",
46-
"fancy-test": "^0.6.4",
45+
"eslint-config-anycli": "^1.3.0",
46+
"fancy-test": "^0.6.5",
4747
"husky": "^0.14.3",
4848
"mocha": "^5.0.0",
4949
"mocha-junit-reporter": "^1.17.0",
5050
"nps": "^5.7.1",
5151
"nps-utils": "^1.5.0",
5252
"ts-node": "^4.1.0",
53-
"typescript": "^2.6.2"
53+
"typescript": "^2.7.1"
5454
},
5555
"engines": {
5656
"node": ">=8.0.0"

src/action/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const stdmockWrite = {
1919
}
2020

2121
export class ActionBase {
22-
type: ActionType
22+
type!: ActionType
2323
std: 'stdout' | 'stderr' = 'stdout'
2424
protected stdmocks?: ['stdout' | 'stderr', string[]][]
2525

src/action/spinner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function color(s: string): string {
1717
export default class SpinnerAction extends ActionBase {
1818
public type: ActionType = 'spinner'
1919

20-
spinner: number
20+
spinner?: number
2121
frames: any
2222
frameIndex: number
2323

@@ -41,13 +41,13 @@ export default class SpinnerAction extends ActionBase {
4141

4242
protected _stop(status: string) {
4343
if (this.task) this.task.status = status
44-
clearInterval(this.spinner)
44+
if (this.spinner) clearInterval(this.spinner)
4545
this._render()
4646
this.output = undefined
4747
}
4848

4949
protected _pause(icon?: string) {
50-
clearInterval(this.spinner)
50+
if (this.spinner) clearInterval(this.spinner)
5151
this._reset()
5252
if (icon) this._render(` ${icon}`)
5353
this.output = undefined

src/errors.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function displayError(err: CLIError) {
100100
}
101101

102102
export class CLIError extends Error {
103-
code: string
103+
code?: string
104104
'cli-ux': {
105105
severity: 'fatal' | 'error' | 'warn'
106106
exit: number | false
@@ -180,9 +180,14 @@ export default (e: IEventEmitter) => {
180180

181181
return (severity: 'fatal' | 'error' | 'warn') => (input: Error | string, opts: Options = {}) => {
182182
if (!input) return
183+
if (isCLIError(input)) throw input
183184
const error = new CLIError(input, severity, opts)
184185
const msg: Message = {type: 'error', severity, error}
185186
e.emit('output', msg)
186187
if (error['cli-ux'].exit !== false) throw error
187188
}
188189
}
190+
191+
function isCLIError(input: any): input is CLIError {
192+
return input['cli-ux']
193+
}

0 commit comments

Comments
 (0)