From b37afd25d45bc906605821c0f712619b6e6969df Mon Sep 17 00:00:00 2001 From: amirrezaask Date: Sat, 5 Dec 2020 13:37:04 +0330 Subject: [PATCH 1/2] add .Error method to error struct --- bootstrap/pkg/core/errors.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bootstrap/pkg/core/errors.go b/bootstrap/pkg/core/errors.go index 8b9b5d9..ae536ab 100644 --- a/bootstrap/pkg/core/errors.go +++ b/bootstrap/pkg/core/errors.go @@ -43,6 +43,10 @@ func (e *Error) ToDebugStr() string { return e.msg } +func (e *Error) Error() string { + return e.msg +} + func MakeError(rt *Runtime, msg string) IError { return &Error{ msg: msg, From 214393870549495d9e857579006bb736569edc63 Mon Sep 17 00:00:00 2001 From: amirrezaask Date: Sat, 5 Dec 2020 14:43:49 +0330 Subject: [PATCH 2/2] add wrapped error --- bootstrap/pkg/core/errors.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bootstrap/pkg/core/errors.go b/bootstrap/pkg/core/errors.go index ae536ab..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,7 +42,16 @@ func (e *Error) String() string { } func (e *Error) ToDebugStr() string { - return e.msg + _, 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 {