[Bootstrap] Add E0003 and the MakeRuntimeError to cover for MakeError
This commit is contained in:
parent
c30c93442b
commit
f2241cc31f
|
@ -63,6 +63,7 @@ type IError interface {
|
||||||
IDebuggable
|
IDebuggable
|
||||||
|
|
||||||
GetErrType() ErrType
|
GetErrType() ErrType
|
||||||
|
GetErrno() errors.Errno
|
||||||
GetDescription() *string
|
GetDescription() *string
|
||||||
GetStackTrace() *TraceBack
|
GetStackTrace() *TraceBack
|
||||||
// To wrap Golan rrrrors
|
// To wrap Golan rrrrors
|
||||||
|
@ -116,6 +117,10 @@ func (e *Error) GetStackTrace() *TraceBack {
|
||||||
return e.trace
|
return e.trace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Error) GetErrno() errors.Errno {
|
||||||
|
return e.errno
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Error) GetDescription() *string {
|
func (e *Error) GetDescription() *string {
|
||||||
desc, ok := errors.ErrorsDescription[e.errno]
|
desc, ok := errors.ErrorsDescription[e.errno]
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -136,8 +141,6 @@ func MakePlainError(msg string) IError {
|
||||||
// the root of the error.
|
// the root of the error.
|
||||||
func MakeError(rt *Runtime, e IExpr, msg string) IError {
|
func MakeError(rt *Runtime, e IExpr, msg string) IError {
|
||||||
rt.Stack.Push(e, rt.Stack.GetCurrentFn())
|
rt.Stack.Push(e, rt.Stack.GetCurrentFn())
|
||||||
// frame := MakeFrame(e, rt.Stack.GetCurrentFn(), 1)
|
|
||||||
// trace := append(*rt.Stack.ToTraceBack(), frame)
|
|
||||||
|
|
||||||
return &Error{
|
return &Error{
|
||||||
Node: MakeNodeFromExpr(e),
|
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 {
|
func MakeSyntaxErrorf(n Node, msg string, a ...interface{}) IError {
|
||||||
return &Error{
|
return &Error{
|
||||||
Node: n,
|
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 {
|
func MakeSemanticError(rt *Runtime, e IExpr, errno errors.Errno, msg string) IError {
|
||||||
//currentFn := rt.Stack.GetCurrentFn()
|
|
||||||
rt.Stack.Push(e, rt.Stack.GetCurrentFn())
|
rt.Stack.Push(e, rt.Stack.GetCurrentFn())
|
||||||
frames := &[]*Frame{
|
frames := &[]*Frame{
|
||||||
//MakeFrame(e, currentFn, 1),
|
|
||||||
rt.Stack.Pop(),
|
rt.Stack.Pop(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,9 +99,10 @@ func evalForm(rt *Runtime, scope IScope, form IExpr) (IExpr, IError) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if expr == nil {
|
if expr == nil {
|
||||||
return nil, MakeError(
|
return nil, MakeRuntimeError(
|
||||||
rt,
|
rt,
|
||||||
sym,
|
sym,
|
||||||
|
errors.E0003,
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"can't resolve symbol '%s' in ns '%s'",
|
"can't resolve symbol '%s' in ns '%s'",
|
||||||
symbolName,
|
symbolName,
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
|
"serene-lang.org/bootstrap/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func toRepresanbleString(ast ...IRepresentable) string {
|
func toRepresanbleString(ast ...IRepresentable) string {
|
||||||
|
@ -169,7 +170,17 @@ func printErrorWithTraceBack(rt *Runtime, err IError) {
|
||||||
}
|
}
|
||||||
loc := err.GetLocation()
|
loc := err.GetLocation()
|
||||||
errTag := color.Red.Sprint(err.GetErrType().String())
|
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) {
|
func PrintError(rt *Runtime, err IError) {
|
||||||
|
|
|
@ -26,8 +26,18 @@ const (
|
||||||
E0000 Errno = iota // THE DESCRIPTION IS NOT SET
|
E0000 Errno = iota // THE DESCRIPTION IS NOT SET
|
||||||
E0001
|
E0001
|
||||||
E0002
|
E0002
|
||||||
|
E0003
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (e Errno) String() string {
|
||||||
|
return [...]string{
|
||||||
|
"E0000",
|
||||||
|
"E0001",
|
||||||
|
"E0002",
|
||||||
|
"E0003",
|
||||||
|
}[e]
|
||||||
|
}
|
||||||
|
|
||||||
var ErrorsDescription map[Errno]string = map[Errno]string{
|
var ErrorsDescription map[Errno]string = map[Errno]string{
|
||||||
E0000: `Can't find any description for this error.`,
|
E0000: `Can't find any description for this error.`,
|
||||||
E0001: `
|
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.
|
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
|
To fix the problem double check the function signature and make sure
|
||||||
that you're passing the correct number of arguments to it`,
|
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.
|
||||||
|
`,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue