github.com/criteo/command-launcher@v0.0.0-20230407142452-fb616f546e98/internal/helper/errors.go (about) 1 package helper 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/fatih/color" 8 ) 9 10 // A contextual help error not only provides the error message, but also a suggestion 11 // for user to correct them in the next command 12 // 13 // for example, when command fails to find necessary files in the workspace, 14 // an actionable error will be helpful to remind the user double check the workspace, 15 // or specify a different one with dedicated flag 16 func ContextualHelpError(err error, suggestions ...string) error { 17 suggestionsText := strings.Join(suggestions, "\n") 18 return fmt.Errorf("%s\n%s", err.Error(), color.MagentaString(suggestionsText)) 19 }