Merge pull request 'Improve internal Error' (#2) from refactor/make-IError-stdlib-compatible into master
Reviewed-on: Serene/Serene#2 Reviewed-by: Sameer Rahmani <lxsameer@gnu.org>
This commit is contained in:
commit
5dbe96b79e
|
@ -28,11 +28,13 @@ type IError interface {
|
||||||
ast.ILocatable
|
ast.ILocatable
|
||||||
IPrintable
|
IPrintable
|
||||||
IDebuggable
|
IDebuggable
|
||||||
|
WithError(err error) IError
|
||||||
}
|
}
|
||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Node
|
Node
|
||||||
msg string
|
WrappedErr error
|
||||||
|
msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Error) String() string {
|
func (e *Error) String() string {
|
||||||
|
@ -40,6 +42,19 @@ func (e *Error) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Error) ToDebugStr() string {
|
func (e *Error) ToDebugStr() string {
|
||||||
|
_, isInternalErr := e.WrappedErr.(*Error)
|
||||||
|
if isInternalErr {
|
||||||
|
return fmt.Sprintf("%s:\n\t%s", e.msg, e.WrappedErr.(*Error).ToDebugStr())
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s:\n\t%s", e.msg, e.WrappedErr.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Error) WithError(err error) IError {
|
||||||
|
e.WrappedErr = err
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Error) Error() string {
|
||||||
return e.msg
|
return e.msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue