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 2fbdd90 commit a2dfde7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 106 deletions.
117 changes: 13 additions & 104 deletions source/err/errorfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1397,15 +1397,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"init/external/source": {
Message: func(tok *token.Token, args ...any) string {
return "can't get source " + emph(args[0]) + "for external service"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return `Pipefish can't open the specified file.`
},
},

"init/func/body": {
Message: func(tok *token.Token, args ...any) string {
return "function definition has no body"
Expand Down Expand Up @@ -1760,25 +1751,9 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"init/source/a": {
Message: func(tok *token.Token, args ...any) string {
return "unable to get source " + emph(args[0]) + " with error " + emph(args[1])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The initializer can't retrieve the source code for the given file. Check that it exists."
},
},

"init/source/b": {
Message: func(tok *token.Token, args ...any) string {
return "unable to get source " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The initializer can't retrieve the source code for the given file. Check that it exists."
},
},

"init/source/c": {
"init/source": {
Message: func(tok *token.Token, args ...any) string {
return "unable to get source " + emph(args[0])
},
Expand Down Expand Up @@ -1841,15 +1816,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"init/unfinished": {
Message: func(tok *token.Token, args ...any) string {
return "unfinished business at end of script"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "It looks like you started a function definition but didn't finish it."
},
},

"lex/bin": {
Message: func(tok *token.Token, args ...any) string {
return "invalid binary token"
Expand Down Expand Up @@ -2171,16 +2137,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"parse/int": {
Message: func(tok *token.Token, args ...any) string {
return "Couldn't parse '" + tok.Literal + "' as integer"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Something about the form of '" + tok.Literal + "' has persuaded Pipefish to try and parse it " +
"as an integer, and yet it is not an integer so Pipefish has failed."
},
},

"parse/line": {
Message: func(tok *token.Token, args ...any) string {
return "Pipefish expected an expression before the end of the line"
Expand All @@ -2191,16 +2147,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"parse/malfunc": {
Message: func(tok *token.Token, args ...any) string {
return "malformed 'func' expression"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This error pretty much speaks for itself: whatever you put after 'func' was in fact just " +
"too plain weird for Pipefish to interpret as a function definition."
},
},

"parse/match": {
Message: func(tok *token.Token, args ...any) string {
return text.DescribeTok(tok) + " doesn't close anything"
Expand Down Expand Up @@ -2271,33 +2217,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"parse/raw/form": {
Message: func(tok *token.Token, args ...any) string {
return "malformed signature"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Something's gone wrong with your syntax around the word 'raw', so that Pipefish isn't sure what you want to do."
},
},

"parse/raw/ident": {
Message: func(tok *token.Token, args ...any) string {
return "expected identifier, not " + text.DescribeTok(tok)
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Pipefish was expecting the name of a parameter at that point in the function declaration."
},
},

"parse/raw/type": {
Message: func(tok *token.Token, args ...any) string {
return "no such type as " + text.DescribeTok(tok)
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The 'raw' suffix must be attached either directly to the name of a parameter, or to a Pipefish type."
},
},

"parse/ret/a": {
Message: func(tok *token.Token, args ...any) string {
return "unexpected occurrence of " + text.DescribeTok(tok) + " in return types"
Expand Down Expand Up @@ -2531,15 +2450,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"sql/": {
Message: func(tok *token.Token, args ...any) string {
return "unable to parse Pipefish in SQL snippet"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Your SQL contains an expression of the form '|...|', which Pipefish is attempting to interpret as being in the Pipefish language. However, the parser isn't able to parse it."
},
},

"sql/conv": {
Message: func(tok *token.Token, args ...any) string {
return "unable to perform type conversion"
Expand Down Expand Up @@ -2603,12 +2513,12 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"sql/sig": {
"sql/": {
Message: func(tok *token.Token, args ...any) string {
return "can't convert Pipefish struct to SQL table"
return "unable to parse Pipefish in SQL snippet"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Recall that only a limited number of types have been implemented for demonstration purposes."
return "Your SQL contains an expression of the form '|...|', which Pipefish is attempting to interpret as being in the Pipefish language. However, the parser isn't able to parse it."
},
},

Expand All @@ -2630,6 +2540,15 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"sql/sig": {
Message: func(tok *token.Token, args ...any) string {
return "can't convert Pipefish struct to SQL table"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Recall that only a limited number of types have been implemented for demonstration purposes."
},
},

"sql/struct": {
Message: func(tok *token.Token, args ...any) string {
return "can't convert type " + text.DescribeTok(tok) + " to SQL table"
Expand Down Expand Up @@ -3295,16 +3214,6 @@ var ErrorCreatorMap = map[string]ErrorCreator{
return fmt.Sprintf("The key of a map cannot be of a struct type.")
},
},

"vm/varchar": {
Message: func(tok *token.Token, args ...any) string {
return "varchar limit exceeded"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The function you are trying to pass the string to has a parameter with a varchar type which restricts how long " +
"a string you can pass to it, and you have exceeded that limit."
},
},
}

func blame(errors Errors, pos int, args ...string) string {
Expand Down
2 changes: 1 addition & 1 deletion source/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (iz *initializer) ParseEverythingFromSourcecode(mc *vm.Vm, cpb *parser.Comm
!testing.Testing() && !(len(scriptFilepath) >= 11 && scriptFilepath[:11] == "test-files/") {
file, err := os.Stat(text.MakeFilepath(scriptFilepath))
if err != nil {
iz.Throw("init/source/b", LINKING_TOKEN, scriptFilepath)
iz.Throw("init/source", LINKING_TOKEN, scriptFilepath)
return nil
}
iz.cp.Timestamp = file.ModTime().UnixMilli()
Expand Down
2 changes: 1 addition & 1 deletion source/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (l *Lexer) NextToken() token.Token {
case '\'':
r, ok := l.readRune()
if !ok {
return l.Throw("lex/rune")
return l.Throw("lex/quote/rune")
}
return l.NewToken(token.RUNE, r)
case '.':
Expand Down

0 comments on commit a2dfde7

Please sign in to comment.