waveterm/waveshell/pkg/base/errors.go
Mike Sawka 4357bcf1c8
implement /reset:cwd (fix for #278) and more (#392)
* checkpoint some ideas on a new branch

* checkpoint on new errors / errorcode passing

* get CodedError piped all the way through to infomsg

* implement a /reset:cwd command to deal with cases when the cwd is invalid.  other assorted debugging, utility, and fixups

* on invalid cwd, show message to run /reset:cwd
2024-03-06 16:37:54 -08:00

38 lines
660 B
Go

package base
import "fmt"
type CodedError struct {
ErrorCode string
Err error
}
func (c *CodedError) Error() string {
return fmt.Sprintf("%s %s", c.ErrorCode, c.Err.Error())
}
func (c *CodedError) Unwrap() error {
return c.Err
}
func MakeCodedError(code string, err error) *CodedError {
return &CodedError{
ErrorCode: code,
Err: err,
}
}
func CodedErrorf(code string, format string, args ...interface{}) *CodedError {
return &CodedError{
ErrorCode: code,
Err: fmt.Errorf(format, args...),
}
}
func GetErrorCode(err error) string {
if codedErr, ok := err.(*CodedError); ok {
return codedErr.ErrorCode
}
return ""
}