diff --git a/bootstrap/pkg/core/errors.go b/bootstrap/pkg/core/errors.go index 7d118d9..95a43bf 100644 --- a/bootstrap/pkg/core/errors.go +++ b/bootstrap/pkg/core/errors.go @@ -63,6 +63,7 @@ type IError interface { IDebuggable GetErrType() ErrType + GetErrno() errors.Errno GetDescription() *string GetStackTrace() *TraceBack // To wrap Golan rrrrors @@ -116,6 +117,10 @@ func (e *Error) GetStackTrace() *TraceBack { return e.trace } +func (e *Error) GetErrno() errors.Errno { + return e.errno +} + func (e *Error) GetDescription() *string { desc, ok := errors.ErrorsDescription[e.errno] if ok { @@ -136,8 +141,6 @@ func MakePlainError(msg string) IError { // the root of the error. func MakeError(rt *Runtime, e IExpr, msg string) IError { rt.Stack.Push(e, rt.Stack.GetCurrentFn()) - // frame := MakeFrame(e, rt.Stack.GetCurrentFn(), 1) - // trace := append(*rt.Stack.ToTraceBack(), frame) return &Error{ Node: MakeNodeFromExpr(e), @@ -147,6 +150,19 @@ func MakeError(rt *Runtime, e IExpr, msg string) IError { } } +func MakeRuntimeError(rt *Runtime, e IExpr, errno errors.Errno, msg string) IError { + rt.Stack.Push(e, rt.Stack.GetCurrentFn()) + + return &Error{ + Node: MakeNodeFromExpr(e), + errtype: RuntimeError, + msg: msg, + errno: errno, + trace: rt.Stack.ToTraceBack(), + } + +} + func MakeSyntaxErrorf(n Node, msg string, a ...interface{}) IError { return &Error{ Node: n, @@ -156,10 +172,8 @@ func MakeSyntaxErrorf(n Node, msg string, a ...interface{}) IError { } func MakeSemanticError(rt *Runtime, e IExpr, errno errors.Errno, msg string) IError { - //currentFn := rt.Stack.GetCurrentFn() rt.Stack.Push(e, rt.Stack.GetCurrentFn()) frames := &[]*Frame{ - //MakeFrame(e, currentFn, 1), rt.Stack.Pop(), } diff --git a/bootstrap/pkg/core/eval.go b/bootstrap/pkg/core/eval.go index c746e26..4a94df7 100644 --- a/bootstrap/pkg/core/eval.go +++ b/bootstrap/pkg/core/eval.go @@ -99,9 +99,10 @@ func evalForm(rt *Runtime, scope IScope, form IExpr) (IExpr, IError) { } if expr == nil { - return nil, MakeError( + return nil, MakeRuntimeError( rt, sym, + errors.E0003, fmt.Sprintf( "can't resolve symbol '%s' in ns '%s'", symbolName, diff --git a/bootstrap/pkg/core/printer.go b/bootstrap/pkg/core/printer.go index 436e7e8..da45078 100644 --- a/bootstrap/pkg/core/printer.go +++ b/bootstrap/pkg/core/printer.go @@ -23,6 +23,7 @@ import ( "strings" "github.com/gookit/color" + "serene-lang.org/bootstrap/pkg/errors" ) func toRepresanbleString(ast ...IRepresentable) string { @@ -169,7 +170,17 @@ func printErrorWithTraceBack(rt *Runtime, err IError) { } loc := err.GetLocation() errTag := color.Red.Sprint(err.GetErrType().String()) - fmt.Printf("%s: %s\nAt: %d to %d\n", errTag, err.String(), loc.GetStart(), loc.GetEnd()) + fmt.Printf( + "%s: %s\nAt: %d to %d\n", + errTag, + err.String(), + loc.GetStart(), + loc.GetEnd(), + ) + if err.GetErrno() != errors.E0000 { + fmt.Printf("For more information on this error try: `serene explain %s`\n", err.GetErrno()) + } + } func PrintError(rt *Runtime, err IError) { diff --git a/bootstrap/pkg/errors/errors.go b/bootstrap/pkg/errors/errors.go index fbab23f..61c5786 100644 --- a/bootstrap/pkg/errors/errors.go +++ b/bootstrap/pkg/errors/errors.go @@ -26,8 +26,18 @@ const ( E0000 Errno = iota // THE DESCRIPTION IS NOT SET E0001 E0002 + E0003 ) +func (e Errno) String() string { + return [...]string{ + "E0000", + "E0001", + "E0002", + "E0003", + }[e] +} + var ErrorsDescription map[Errno]string = map[Errno]string{ E0000: `Can't find any description for this error.`, E0001: ` @@ -51,4 +61,11 @@ Functions expect a certain number of argument. The number of arguments that you're passing to the function doesn't match with it's signature. To fix the problem double check the function signature and make sure that you're passing the correct number of arguments to it`, + E0003: ` +Do you have a typo ? Or did you forget to define a symbol that you're trying +to evaluate ? + +This error happens when the symbol that you're trying to evaluate is not +associated with any value in the current scope tree. +`, }