diff --git a/bootstrap/pkg/core/errors.go b/bootstrap/pkg/core/errors.go index 8b9b5d9..6f9d441 100644 --- a/bootstrap/pkg/core/errors.go +++ b/bootstrap/pkg/core/errors.go @@ -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 }