Skip to content

Commit

Permalink
Add more error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
peachpit-site committed Jan 31, 2025
1 parent fcd4329 commit 72ba75f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 114 deletions.
2 changes: 1 addition & 1 deletion source/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,7 @@ func (cp *Compiler) compileSnippet(tok *token.Token, newEnv *Environment, csk vm
bindle := vm.SnippetBindle{Csk: csk}
bits, ok := text.GetTextWithBarsAsList(sText)
if !ok {
cp.P.Throw("comp/snippet/form/b", tok)
cp.P.Throw("comp/snippet/form", tok)
return &bindle
}
var buf strings.Builder
Expand Down
124 changes: 11 additions & 113 deletions source/err/errorfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"comp/call": {
Message: func(tok *token.Token, args ...any) string {
return "No implementation of function " + emph(tok.Literal) + " exists for the given types"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "You have supplied the function with arguments of types for which no function of that name is defined."
},
},

"comp/command": {
Message: func(tok *token.Token, args ...any) string {
return "trying to access a command " + emph(tok.Literal) + " from a function"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Functions can only call other functions, whereas commands can call both functions and commands."
},
},

"comp/continue": {
Message: func(tok *token.Token, args ...any) string {
return "'continue' outside of 'for' loop"
Expand Down Expand Up @@ -331,15 +313,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"comp/error/return": {
Message: func(tok *token.Token, args ...any) string {
return "function can only return error"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This function is written so that it can never return anything but an error. Pipefish assumes that this is a mistake."
},
},

"comp/eq/types": {
Message: func(tok *token.Token, args ...any) string {
return "can't compare values of different types"
Expand Down Expand Up @@ -720,24 +693,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"comp/loop/body": {
Message: func(tok *token.Token, args ...any) string {
return "trying to return a value from an imperative loop"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The body of a loop should consist only of imperative instructions. It cannot return any value except an error."
},
},

"comp/loop/infinite": {
Message: func(tok *token.Token, args ...any) string {
return "look cannot terminate"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This loop can neither return an error nor encounter a " + emph("break") + " statement, and so can never halt."
},
},

"comp/namespace/exist": {
Message: func(tok *token.Token, args ...any) string {
return "unknown namespace " + emph(args[0])
Expand Down Expand Up @@ -921,26 +876,7 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"comp/splat/type": {
Message: func(tok *token.Token, args ...any) string {
return "argument of '...' must be list or listlike, not " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The purpose of the splat operator '...' is to expand a list or " +
"listlike value into a tuple. You're applying it to the wrong type."
},
},

"comp/snippet/form/a": {
Message: func(tok *token.Token, args ...any) string {
return "unmatched " + emph("|") + " in snippet constructor"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Pipefish interprets " + emph("| <expression> |") + " in a snippet constructor as meaning that the expression should be evaluated. It therefore expects the " + emph("|") + " symbols to come in matching pairs."
},
},

"comp/snippet/form/b": {
"comp/snippet/form": {
Message: func(tok *token.Token, args ...any) string {
return "unmatched " + emph("|") + " in snippet constructor"
},
Expand Down Expand Up @@ -976,6 +912,16 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"comp/splat/type": {
Message: func(tok *token.Token, args ...any) string {
return "argument of '...' must be list or listlike, not " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The purpose of the splat operator '...' is to expand a list or " +
"listlike value into a tuple. You're applying it to the wrong type."
},
},

"comp/typecheck/error": {
Message: func(tok *token.Token, args ...any) string {
return "expression can only have error type"
Expand Down Expand Up @@ -1076,34 +1022,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"comp/var/exist": {
Message: func(tok *token.Token, args ...any) string {
return "unknown identifier " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "You don't seem to have declared that as a variable, function, constant, or anything else."
},
},

"comp/var/var": {
Message: func(tok *token.Token, args ...any) string {
return "trying to change value of constant " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Having declared that value as constant, you are not allowed to change it. If you want to, define it in the " + emph("var") + " section instead."
},
},

"comp/varargs": {
Message: func(tok *token.Token, args ...any) string {
return "unexpected occurrence of " + emph("...")
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The " + emph("...") + " token is meaningful only in the signature of a function, command, or assignment, where '<parameterName> <typename>...' indicates " +
"that the parameter can accept any number of arguments of the given type, e.g. " + emph("foo(numbers int...)") + ". It is meaningless in an ordinary statement or expression."
},
},

"err/misdirect": {
Message: func(tok *token.Token, args ...any) string {
return "Pipefish is trying and failing to raise an error with reference " + emph(args[0])
Expand Down Expand Up @@ -1269,26 +1187,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"golang/found": {
Message: func(tok *token.Token, args ...any) string {
return "couldn't find Go function '" + args[0].(string) + "'"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Pipefish's system for handling functions written in Go has broken down.\n\n" +
"There are no circumstances under which you should actually see this error: if you ever " +
"do, please err it to the author of Pipefish as an issue."
},
},

"golang/namespace": {
Message: func(tok *token.Token, args ...any) string {
return "can't find namespace " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The Golang type converter can't find the specified namespace."
},
},

"golang/type/a": {
Message: func(tok *token.Token, args ...any) string {
return "can't pass value of type " + emph(args[0]) + " to Go as value"
Expand Down

0 comments on commit 72ba75f

Please sign in to comment.