Skip to content

Commit 60092f2

Browse files
committed
Add more error messages
1 parent 4961c1f commit 60092f2

File tree

2 files changed

+163
-3
lines changed

2 files changed

+163
-3
lines changed

source/err/errorfile.go

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,26 @@ var ErrorCreatorMap = map[string]ErrorCreator{
25852585
},
25862586
},
25872587

2588+
"vm/cast/a": {
2589+
Message: func(tok *token.Token, args ...any) string {
2590+
return "unable to perform cast"
2591+
},
2592+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2593+
return "Types can only be cast between clones of the same parent, or the " +
2594+
"parent itself."
2595+
},
2596+
},
2597+
2598+
"vm/cast/b": {
2599+
Message: func(tok *token.Token, args ...any) string {
2600+
return "unable to perform cast"
2601+
},
2602+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2603+
return "Types can only be cast between clones of the same parent, or the " +
2604+
"parent itself."
2605+
},
2606+
},
2607+
25882608
"vm/div/float": {
25892609
Message: func(tok *token.Token, args ...any) string {
25902610
return "division by zero"
@@ -2603,6 +2623,71 @@ var ErrorCreatorMap = map[string]ErrorCreator{
26032623
},
26042624
},
26052625

2626+
"vm/for/type/a": {
2627+
Message: func(tok *token.Token, args ...any) string {
2628+
return "can't range over given type"
2629+
},
2630+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2631+
return "You can range over lists, strings, maps, sets, and enums."
2632+
},
2633+
},
2634+
2635+
"vm/for/type/b": {
2636+
Message: func(tok *token.Token, args ...any) string {
2637+
return "can't range over given type"
2638+
},
2639+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2640+
return "You can range over lists, strings, maps, sets, and enums."
2641+
},
2642+
},
2643+
2644+
"vm/for/type/c": {
2645+
Message: func(tok *token.Token, args ...any) string {
2646+
return "can't range over given type"
2647+
},
2648+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2649+
return "You can range over lists, strings, maps, sets, and enums."
2650+
},
2651+
},
2652+
2653+
"vm/for/pair": {
2654+
Message: func(tok *token.Token, args ...any) string {
2655+
return "range should be pair of integers"
2656+
},
2657+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2658+
return "If you're going to give the range of a list using `::`, the elements of the pair should both be integers."
2659+
},
2660+
},
2661+
2662+
"vm/func/args": {
2663+
Message: func(tok *token.Token, args ...any) string {
2664+
return "lambda function has the wrong number of arguments"
2665+
},
2666+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2667+
return "The arguments passed are different in number from the parameters of the function."
2668+
},
2669+
},
2670+
2671+
"vm/func/go": {
2672+
Message: func(tok *token.Token, args ...any) string {
2673+
return "failed to convert Pipefish value"
2674+
},
2675+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2676+
return "You're trying to apply a Go lambda function (wrapped in a Pipefish " +
2677+
"lambda function), to something that Pipefish doesn't know how to convert " +
2678+
"into Go."
2679+
},
2680+
},
2681+
2682+
"vm/func/types": {
2683+
Message: func(tok *token.Token, args ...any) string {
2684+
return "function has the wrong types"
2685+
},
2686+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2687+
return "The arguments passed are different in type from the parameters of the function."
2688+
},
2689+
},
2690+
26062691
"vm/go/type": {
26072692
Message: func(tok *token.Token, args ...any) string {
26082693
return "can't convert Go value of type " + emph(args[0]) + " to Pipefish"
@@ -2819,6 +2904,15 @@ var ErrorCreatorMap = map[string]ErrorCreator{
28192904
},
28202905
},
28212906

2907+
"vm/index/q": {
2908+
Message: func(tok *token.Token, args ...any) string {
2909+
return fmt.Sprintf("out of range: can't index value of type %v by %v", emph(args[0]), emph(args[1]))
2910+
},
2911+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2912+
return fmt.Sprintf("Pipefish just can't make sense of that at all.")
2913+
},
2914+
},
2915+
28222916
"vm/label/exist": {
28232917
Message: func(tok *token.Token, args ...any) string {
28242918
return fmt.Sprintf("can't convert string %v to a label", emphStr(args[0]))
@@ -2846,6 +2940,16 @@ var ErrorCreatorMap = map[string]ErrorCreator{
28462940
},
28472941
},
28482942

2943+
"vm/mf/lhs": {
2944+
Message: func(tok *token.Token, args ...any) string {
2945+
return "expected value of type 'list'"
2946+
},
2947+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2948+
return "The value on the left-hand side of the operators '?>' and '>>' " +
2949+
"should always be of type 'list'."
2950+
},
2951+
},
2952+
28492953
"vm/mod/int": {
28502954
Message: func(tok *token.Token, args ...any) string {
28512955
return "taking the modulus of a number by zero"
@@ -2855,6 +2959,15 @@ var ErrorCreatorMap = map[string]ErrorCreator{
28552959
},
28562960
},
28572961

2962+
"vm/oopsie": {
2963+
Message: func(tok *token.Token, args ...any) string {
2964+
return "something unexpected has gone wrong"
2965+
},
2966+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2967+
return "Please tell the author of Pipefish that he messed up. Thank you."
2968+
},
2969+
},
2970+
28582971
"vm/pipe/filter/bool": {
28592972
Message: func(tok *token.Token, args ...any) string {
28602973
return "right-hand side of filter expression cannot return boolean"
@@ -3017,6 +3130,43 @@ var ErrorCreatorMap = map[string]ErrorCreator{
30173130
},
30183131
},
30193132

3133+
"vm/splat/type": {
3134+
Message: func(tok *token.Token, args ...any) string {
3135+
return "expected value of type 'list'"
3136+
},
3137+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
3138+
return "The value on the left-hand side of the splat operator '...' " +
3139+
"should always be of type 'list'."
3140+
},
3141+
},
3142+
3143+
"vm/tup/first": {
3144+
Message: func(tok *token.Token, args ...any) string {
3145+
return "trying to take the first element of an empty tuple"
3146+
},
3147+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
3148+
return "The empty tuple '()' has no first element."
3149+
},
3150+
},
3151+
3152+
"vm/tup/last": {
3153+
Message: func(tok *token.Token, args ...any) string {
3154+
return "trying to take the last element of an empty tuple"
3155+
},
3156+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
3157+
return "The empty tuple '()' has no last element."
3158+
},
3159+
},
3160+
3161+
"vm/typecheck": {
3162+
Message: func(tok *token.Token, args ...any) string {
3163+
return "failed typecheck"
3164+
},
3165+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
3166+
return "You placed constraints on the types of this expression which you then violated."
3167+
},
3168+
},
3169+
30203170
"vm/types/a": {
30213171
Message: func(tok *token.Token, args ...any) string {
30223172
return "No implementation of function " + emph(tok.Literal) + " exists for the given types"
@@ -3053,6 +3203,16 @@ var ErrorCreatorMap = map[string]ErrorCreator{
30533203
},
30543204
},
30553205

3206+
"vm/unwrap": {
3207+
Message: func(tok *token.Token, args ...any) string {
3208+
return "trying to unwrap something that isn't an 'error'"
3209+
},
3210+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
3211+
return "The 'unwrap' function converts things of type 'error' into type 'Error': " +
3212+
"it doesn't work on anything else."
3213+
},
3214+
},
3215+
30563216
"vm/with/a": {
30573217
Message: func(tok *token.Token, args ...any) string {
30583218
return fmt.Sprintf("type %v found indexing list in %v expression where %v was expected", emph(args[0]), emph("with"), emph("int"))

source/vm/vm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ loop:
377377
pfArg := vm.Mem[pfMemLoc]
378378
goArg, ok := vm.pipefishToGo(pfArg)
379379
if !ok {
380-
vm.Mem[args[0]] = values.Value{values.ERROR, err.CreateErr("vm/func/go", lambda.Tok, goArg)} // If the conversion failed, the goArg will be the Pipefish value it couldn't convert.
380+
vm.Mem[args[0]] = values.Value{values.ERROR, err.CreateErr("vm/func/go", lambda.Tok, goArg)} // If the conversion failed, the goArg will be the value it couldn't convert.
381381
break Switch
382382
}
383383
goArgs = append(goArgs, reflect.ValueOf(goArg))
@@ -2043,7 +2043,7 @@ func (vm *Vm) NewIterator(container values.Value, keysOnly bool, tokLoc uint32)
20432043
case values.TYPE:
20442044
abTyp := container.V.(values.AbstractType)
20452045
if len(abTyp.Types) != 1 {
2046-
return values.Value{values.ERROR, vm.makeError("vm/for/type/a", tokLoc)}
2046+
return values.Value{values.ERROR, vm.makeError("vm/for/type/a", tokLoc, )}
20472047
}
20482048
typ := abTyp.Types[0]
20492049
if !vm.ConcreteTypeInfo[typ].IsEnum() {
@@ -2055,7 +2055,7 @@ func (vm *Vm) NewIterator(container values.Value, keysOnly bool, tokLoc uint32)
20552055
return values.Value{values.ITERATOR, &values.EnumIterator{Type: typ, Max: len(vm.ConcreteTypeInfo[typ].(EnumType).ElementNames)}}
20562056
}
20572057
default:
2058-
return values.Value{values.ERROR, vm.makeError("vm/for/type", tokLoc)}
2058+
return values.Value{values.ERROR, vm.makeError("vm/for/type/c", tokLoc)}
20592059
}
20602060
}
20612061

0 commit comments

Comments
 (0)