-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2741 from ActiveState/DX-2151
User-facing errors in example runner
- Loading branch information
Showing
9 changed files
with
144 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package errs | ||
|
||
import "errors" | ||
|
||
type UserFacingError interface { | ||
error | ||
UserError() string | ||
} | ||
|
||
type ErrOpt func(err *userFacingError) *userFacingError | ||
|
||
type userFacingError struct { | ||
wrapped error | ||
message string | ||
tips []string | ||
} | ||
|
||
func (e *userFacingError) Error() string { | ||
return "User Facing Error: " + e.UserError() | ||
} | ||
|
||
func (e *userFacingError) UserError() string { | ||
return e.message | ||
} | ||
|
||
func (e *userFacingError) ErrorTips() []string { | ||
return e.tips | ||
} | ||
|
||
func NewUserFacingError(message string, tips ...string) *userFacingError { | ||
return WrapUserFacingError(nil, message) | ||
} | ||
|
||
func WrapUserFacingError(wrapTarget error, message string, opts ...ErrOpt) *userFacingError { | ||
err := &userFacingError{ | ||
wrapTarget, | ||
message, | ||
nil, | ||
} | ||
|
||
for _, opt := range opts { | ||
err = opt(err) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func IsUserFacing(err error) bool { | ||
var userFacingError UserFacingError | ||
return errors.As(err, &userFacingError) | ||
} | ||
|
||
func WithTips(tips ...string) ErrOpt { | ||
return func(err *userFacingError) *userFacingError { | ||
err.tips = append(err.tips, tips...) | ||
return err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package errors | ||
|
||
import "github.com/ActiveState/cli/internal/errs" | ||
|
||
type ErrNoProject struct { | ||
*errs.WrapperError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters