mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-04 18:59:08 +01:00
4357bcf1c8
* 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
38 lines
660 B
Go
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 ""
|
|
}
|