Skip to content

Commit

Permalink
Improve error messaging
Browse files Browse the repository at this point in the history
Update the CLI with better error messaging based on two principles:
- Try to help the user fix the error (achieved e.g. by suggesting to use
  an explicit target when the current working directory can't be
  determined).
- Including the full error which the user can use to debug or in bug
  reports.

Signed-off-by: Eric Cornelissen <ericornelissen@gmail.com>
  • Loading branch information
ericcornelissen committed Mar 9, 2024
1 parent e2cc1ec commit 6edce3f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cmd/ades/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func run() int {
if len(targets) == 0 {
wd, err := os.Getwd()
if err != nil {
fmt.Printf("Unexpected error getting working directory: %s", err)
fmt.Printf("Could not get working directory, use explicit target instead (error: %s)\n", err)
return exitError
}

Expand Down Expand Up @@ -149,12 +149,13 @@ func run() int {
func runOnStdin() (map[string]map[string][]ades.Violation, bool) {
data, err := io.ReadAll(os.Stdin)
if err != nil {
fmt.Printf("Could not read from stdin (error: %s)\n", err)
return nil, false
}

violations := make(map[string][]ades.Violation)
if workflowViolations, err := tryWorkflow(data); err != nil {
fmt.Println("Could not parse input, is it YAML?")
fmt.Printf("Could not parse input (error: %s)\n", err)
return nil, false
} else if len(workflowViolations) != 0 {
violations["stdin"] = workflowViolations
Expand Down
2 changes: 1 addition & 1 deletion test/stdin.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ stdin .github/workflows/unsafe.yml
# Not yaml
stdin not-yaml.txt
! exec ades -
stdout 'Could not parse input, is it YAML?'
stdout 'Could not parse input'
! stdout 'Ok'
! stderr .

Expand Down

0 comments on commit 6edce3f

Please sign in to comment.