29 lines
621 B
Go
29 lines
621 B
Go
|
package cerr
|
||
|
|
||
|
// Error allows you to create constant "const" error with type boxing.
|
||
|
type Error string
|
||
|
|
||
|
// Error implements the error builtin interface.
|
||
|
func (err Error) Error() string {
|
||
|
return string(err)
|
||
|
}
|
||
|
|
||
|
// Wrap returns a new error which wraps a new error into itself.
|
||
|
func (err Error) Wrap(e error) *WrapError {
|
||
|
return &WrapError{
|
||
|
base: err,
|
||
|
wrap: e,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WrapError is way to wrap errors recursively.
|
||
|
type WrapError struct {
|
||
|
base error
|
||
|
wrap error
|
||
|
}
|
||
|
|
||
|
// Error implements the error builtin interface recursively.
|
||
|
func (err *WrapError) Error() string {
|
||
|
return err.base.Error() + ": " + err.wrap.Error()
|
||
|
}
|