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 89a5575 commit 2fbdd90
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
6 changes: 4 additions & 2 deletions source/checkerr.pf
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import
const

// Things that have the right format to be error codes but aren't (or in the case of
// 'vm/user', shouldn't have an error message).
// 'vm/user', shouldn't have an error message, or in the case of 'lex/wsp' appears
// in a '_test.go' file).
FALSE_POSITIVES = set(`"database/sql"`, `"encoding/json"`, `"math/rand"`, `"net/http"`,
.. `"os/exec"`, `"path/filepath"`, `"html/template"`, `"vm/user"`)
.. `"os/exec"`, `"path/filepath"`, `"html/template"`, `"vm/user"`,
.. `"lex/wsp"`)

cmd

Expand Down
19 changes: 19 additions & 0 deletions source/err/errorfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,15 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"ext/deserialize/h": {
Message: func(tok *token.Token, args ...any) string {
return "unable to deserialize message from external service"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This condition should never actually arise. Please contact the author of Pipefish and tell him how it occurred."
},
},

"golang/build": {
Message: func(tok *token.Token, args ...any) string {
return "failed to compile Go\n\nError was '" + args[0].(string) + "'"
Expand Down Expand Up @@ -2022,6 +2031,16 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"lex/quote/rune": {
Message: func(tok *token.Token, args ...any) string {
return "rune litereal unterminated by end of line"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Having begun a rune literal with an opening quote, you haven't concluded it with a matching " +
"closing quote before the end of your line of code."
},
},

"lex/wsp": {
Message: func(tok *token.Token, args ...any) string {
return "whitespace is inconsistent with previous indentation levels"
Expand Down
6 changes: 3 additions & 3 deletions source/initializer/deserializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,21 @@ func (iz *initializer) deserializeTypescheme(s string) compiler.AlternateType {
case compiler.SimpleType:
stack.Push(ty)
default:
iz.Throw("ext/deserialize/e", &token.Token{Source: "Pipefish builder"})
iz.Throw("ext/deserialize/f", &token.Token{Source: "Pipefish builder"})
}
}
}
// We're done.
result, ok := stack.Pop() // We should have one thing left on the stack, which is the answer.
if !ok {
iz.Throw("ext/deserialize/f", &token.Token{Source: "Pipefish builder"})
iz.Throw("ext/deserialize/g", &token.Token{Source: "Pipefish builder"})
return nil
}
switch result := result.(type) { // And it should be an AlternateType.
case compiler.AlternateType:
return result
default:
iz.Throw("ext/deserialize/g", &token.Token{Source: "Pipefish builder"})
iz.Throw("ext/deserialize/h", &token.Token{Source: "Pipefish builder"})
return nil

}
Expand Down
14 changes: 7 additions & 7 deletions 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/quote/c")
return l.Throw("lex/rune")
}
return l.NewToken(token.RUNE, r)
case '.':
Expand Down Expand Up @@ -408,12 +408,12 @@ func (l *Lexer) readSnippet() string {
}
if langIndent == "" { // Then this is the first time around.
if currentWhitespace == "" {
l.Throw("lex/emdash/indent/a", l.NewToken(token.ILLEGAL, "lex/emdash/indent/a"))
l.Throw("lex/emdash/indent/a", l.NewToken(token.ILLEGAL, "bad emdash"))
return result
}
langIndent = currentWhitespace
if langIndent == stackTop {
l.Throw("lex/emdash/indent/b", l.NewToken(token.ILLEGAL, "lex/emdash/indent/b"))
l.Throw("lex/emdash/indent/b", l.NewToken(token.ILLEGAL, "bad emdash"))
return result
}
}
Expand All @@ -424,7 +424,7 @@ func (l *Lexer) readSnippet() string {
return result
}
if !strings.HasPrefix(currentWhitespace, stackTop) && !(currentWhitespace == "\n") {
l.Throw("lex/emdash/indent/c", l.NewToken(token.ILLEGAL, "lex/emdash/indent/c"))
l.Throw("lex/emdash/indent/c", l.NewToken(token.ILLEGAL, "bad emdash"))
return result
}
for l.peekChar() != '\n' && l.peekChar() != 0 {
Expand Down Expand Up @@ -454,22 +454,22 @@ func (l *Lexer) readGolang() string {
}
// We expect a brace or quotes after the golang keyword. (The quotes if it's in the import section, import golang "foo".)
if l.peekChar() != '{' && l.peekChar() != '"' && l.peekChar() != '`' {
l.Throw("lex/golang", l.NewToken(token.ILLEGAL, "lex/golang"))
l.Throw("lex/golang", l.NewToken(token.ILLEGAL, "bad golang"))
return ""
}
if l.peekChar() == '"' {
l.readChar()
s, ok := l.readFormattedString()
if !ok {
l.Throw("lex/quote/c", l.NewToken(token.ILLEGAL, "lex/quote/c"))
l.Throw("lex/quote/c", l.NewToken(token.ILLEGAL, "bad quote"))
}
return s
}
if l.peekChar() == '`' {
l.readChar()
s, ok := l.readPlaintextString()
if !ok {
l.Throw("lex/quote/d", l.NewToken(token.ILLEGAL, "lex/quote/d"))
l.Throw("lex/quote/d", l.NewToken(token.ILLEGAL, "bad quote"))
}
return s
}
Expand Down

0 comments on commit 2fbdd90

Please sign in to comment.