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:
amirrezaask 2020-12-05 11:24:55 +00:00
commit 5dbe96b79e
1 changed files with 16 additions and 1 deletions

View File

@ -28,11 +28,13 @@ type IError interface {
ast.ILocatable
IPrintable
IDebuggable
WithError(err error) IError
}
type Error struct {
Node
msg string
WrappedErr error
msg string
}
func (e *Error) String() string {
@ -40,6 +42,19 @@ func (e *Error) String() 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
}