Skip to content

Commit

Permalink
helper for error results
Browse files Browse the repository at this point in the history
  • Loading branch information
akerl committed Nov 20, 2019
1 parent 1cb6a32 commit d184da4
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions checks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func newSetFromFile(dir, file string) (CheckSet, error) {
input := loadCheckInput{Dir: dir}
err := execProspectusFile(file, "load", input, &cs)
if err != nil {
return CheckSet{}, err
return CheckSet{}, fmt.Errorf("Failed loading %s: %s", file, err)
}
for index := range cs {
cs[index].Dir = dir
Expand Down Expand Up @@ -143,14 +143,7 @@ func execProspectusForResult(method string, c Check, input interface{}) Result {
r := Result{}
err := execProspectusFile(c.File, method, input, &r)
if err != nil {
return Result{
Actual: "error",
Expected: expectations.Wrapper{
Type: "error",
Data: map[string]string{"msg": fmt.Sprintf("%s error: %s", method, err)},
},
Check: c,
}
return NewErrorResult(fmt.Sprintf("%s error: %s", method, err), c)
}
r.Check = c
return r
Expand Down Expand Up @@ -214,3 +207,15 @@ func (r Result) String() string {
func (r Result) Fix() Result {
return execProspectusForResult("fix", r.Check, r)
}

// NewErrorResult creates an error result from a given string
func NewErrorResult(msg string, c Check) Result {
return Result{
Actual: "error",
Expected: expectations.Wrapper{
Type: "error",
Data: map[string]string{"msg": msg},
},
Check: c,
}
}

0 comments on commit d184da4

Please sign in to comment.