Skip to content

Commit

Permalink
fix exit code on format/label not defined errors
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Jan 16, 2021
1 parent 96830fd commit 3d390af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cli/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (err *compileError) Error() string {
}

func (err *compileError) ExitCode() int {
if err, ok := err.err.(interface{ ExitCode() int }); ok {
return err.ExitCode()
}
return exitCodeCompileErr
}

Expand Down
3 changes: 2 additions & 1 deletion cli/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,7 @@
input: '1'
error: |
label not defined: "$test"
exit_code: 3

- name: invalid break name
args:
Expand Down Expand Up @@ -4503,7 +4504,7 @@
- '@foo'
error: |
format not defined: @foo
exit_code: 3
exit_code: 5

- name: destructuring alternative operator
args:
Expand Down
8 changes: 8 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func (err *formatNotFoundError) Error() string {
return fmt.Sprintf("format not defined: %s", err.n)
}

func (err *formatNotFoundError) ExitCode() int {
return 5
}

type formatCsvTsvRowError struct {
typ string
v interface{}
Expand Down Expand Up @@ -221,6 +225,10 @@ func (err *breakError) Error() string {
return fmt.Sprintf(`label not defined: %q`, err.n)
}

func (err *breakError) ExitCode() int {
return 3
}

type stringLiteralError struct {
s string
}
Expand Down

0 comments on commit 3d390af

Please sign in to comment.