Skip to content

Commit

Permalink
improved error reporting details
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Aug 5, 2024
1 parent ae16a3c commit f2dcbc2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
10 changes: 9 additions & 1 deletion env/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1399,14 +1399,22 @@ func (i Error) Inspect(e Idxs) string {
}

func (i Error) Print(e Idxs) string {
return i.Print2(e, 1)
}

func (i Error) Print2(e Idxs, depth int) string {
status := ""
if i.Status != 0 {
status = "(" + strconv.Itoa(i.Status) + ")"
}
var b strings.Builder
b.WriteString("Error" + status + ": " + i.Message + " ")
if i.Parent != nil {
b.WriteString("\n\t" + i.Parent.Print(e))
b.WriteString("\n")
for i := 0; i < depth; i++ {
b.WriteString(" ")
}
b.WriteString(i.Parent.Print2(e, depth+1))
}
for k, v := range i.Values {
switch ob := v.(type) {
Expand Down
4 changes: 2 additions & 2 deletions env/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (ser TSeries) Len() int {
// PositionAndSurroundingElements returns a string of the position of the series, marked with (here) and 10 surrounding elements.
func (ser TSeries) PositionAndSurroundingElements(idxs Idxs) string {
var bu strings.Builder
bu.WriteString("{ ")
bu.WriteString(" ")
st := 0
if ser.Pos() > 10 {
bu.WriteString("... ")
Expand All @@ -130,6 +130,6 @@ func (ser TSeries) PositionAndSurroundingElements(idxs Idxs) string {
if ser.Len() > ser.Pos()+9 {
bu.WriteString("... ")
}
bu.WriteString("}")
bu.WriteString("")
return bu.String()
}
2 changes: 1 addition & 1 deletion evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func MakeArgError(env1 *env.ProgramState, N int, typ []env.Type, fn string) *env
}
types += env.NativeTypes[tt-1]
}
return env.NewError("Function " + fn + " requires argument " + strconv.Itoa(N) + " to be of : " + types + ".")
return env.NewError("builtin `" + fn + "` requires argument " + strconv.Itoa(N) + " to be: " + types + ".")
}

func MakeNativeArgError(env1 *env.ProgramState, N int, knd []string, fn string) *env.Error {
Expand Down
12 changes: 10 additions & 2 deletions evaldo/evaldo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package evaldo

import (
"fmt"
"strconv"

"github.com/refaktor/rye/env"
//"fmt"
Expand Down Expand Up @@ -207,6 +208,10 @@ func EvalExpressionInjLimited(ps *env.ProgramState, inj env.Object, injnow bool)
if ps.ReturnFlag {
return ps, injnow
}
fmt.Println("XY")
if esleft.Res.Type() == env.ErrorType {
fmt.Println("XX")
}
} else {
// otherwise set program state to specific one and injected value to result
// set injnow to false and if return flag return
Expand Down Expand Up @@ -392,7 +397,7 @@ func EvalExpressionConcrete(ps *env.ProgramState) *env.ProgramState {
}
} else {
ps.ErrorFlag = true
ps.Res = env.NewError("expected rye value but got nothing")
ps.Res = env.NewError("expected rye value but it's missing")
}

return ps
Expand Down Expand Up @@ -924,6 +929,7 @@ func CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft
return ps
}
if checkErrorReturnFlag(ps) {
ps.Res = env.NewError4(0, "argument 1 of "+strconv.Itoa(bi.Argsn+1)+" missing of builtin: '"+bi.Doc+"'", ps.Res.(*env.Error), nil)
return ps
}
if ps.Res.Type() == env.VoidType {
Expand All @@ -942,6 +948,7 @@ func CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft
return ps
}
if checkErrorReturnFlag(ps) {
ps.Res = env.NewError4(0, "argument 2 of "+strconv.Itoa(bi.Argsn+1)+" missing of builtin: '"+bi.Doc+"'", ps.Res.(*env.Error), nil)
return ps
}
//fmt.Println(ps.Res)
Expand All @@ -958,6 +965,7 @@ func CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft
return ps
}
if checkErrorReturnFlag(ps) {
ps.Res = env.NewError4(0, "argument 3 missing", ps.Res.(*env.Error), nil)
return ps
}
if ps.Res.Type() == env.VoidType {
Expand Down Expand Up @@ -1103,7 +1111,7 @@ func checkFlagsBi(bi env.Builtin, ps *env.ProgramState, n int) bool {
if bi.AcceptFailure {
trace2("----- > Accept Failure")
} else {
fmt.Println("checkFlagsBi***")
// fmt.Println("checkFlagsBi***")
trace2("Fail -------> Error.")
switch err := ps.Res.(type) {
case env.Error:
Expand Down
5 changes: 4 additions & 1 deletion main_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ var (
func sendMessageToJS(message string) {
jsCallback.Invoke(message)
}
func sendMessageToJSNL(message string) {
jsCallback.Invoke(message + "\n")
}

func sendLineToJS(line string) string {
ret := jsCallback2.Invoke(line)
Expand Down Expand Up @@ -179,7 +182,7 @@ func RyeEvalShellLine(this js.Value, args []js.Value) any {
}

evaldo.EvalBlockInj(ps, prevResult, true)
evaldo.MaybeDisplayFailureOrErrorWASM(ps, ps.Idx, sendMessageToJS)
evaldo.MaybeDisplayFailureOrErrorWASM(ps, ps.Idx, sendMessageToJSNL)

prevResult = ps.Res

Expand Down

0 comments on commit f2dcbc2

Please sign in to comment.