Skip to content

Commit 2fbdd90

Browse files
committed
Add more error messages
1 parent 89a5575 commit 2fbdd90

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

source/checkerr.pf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import
1010
const
1111

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

1719
cmd
1820

source/err/errorfile.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,15 @@ var ErrorCreatorMap = map[string]ErrorCreator{
11041104
},
11051105
},
11061106

1107+
"ext/deserialize/h": {
1108+
Message: func(tok *token.Token, args ...any) string {
1109+
return "unable to deserialize message from external service"
1110+
},
1111+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
1112+
return "This condition should never actually arise. Please contact the author of Pipefish and tell him how it occurred."
1113+
},
1114+
},
1115+
11071116
"golang/build": {
11081117
Message: func(tok *token.Token, args ...any) string {
11091118
return "failed to compile Go\n\nError was '" + args[0].(string) + "'"
@@ -2022,6 +2031,16 @@ var ErrorCreatorMap = map[string]ErrorCreator{
20222031
},
20232032
},
20242033

2034+
"lex/quote/rune": {
2035+
Message: func(tok *token.Token, args ...any) string {
2036+
return "rune litereal unterminated by end of line"
2037+
},
2038+
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
2039+
return "Having begun a rune literal with an opening quote, you haven't concluded it with a matching " +
2040+
"closing quote before the end of your line of code."
2041+
},
2042+
},
2043+
20252044
"lex/wsp": {
20262045
Message: func(tok *token.Token, args ...any) string {
20272046
return "whitespace is inconsistent with previous indentation levels"

source/initializer/deserializer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,21 +217,21 @@ func (iz *initializer) deserializeTypescheme(s string) compiler.AlternateType {
217217
case compiler.SimpleType:
218218
stack.Push(ty)
219219
default:
220-
iz.Throw("ext/deserialize/e", &token.Token{Source: "Pipefish builder"})
220+
iz.Throw("ext/deserialize/f", &token.Token{Source: "Pipefish builder"})
221221
}
222222
}
223223
}
224224
// We're done.
225225
result, ok := stack.Pop() // We should have one thing left on the stack, which is the answer.
226226
if !ok {
227-
iz.Throw("ext/deserialize/f", &token.Token{Source: "Pipefish builder"})
227+
iz.Throw("ext/deserialize/g", &token.Token{Source: "Pipefish builder"})
228228
return nil
229229
}
230230
switch result := result.(type) { // And it should be an AlternateType.
231231
case compiler.AlternateType:
232232
return result
233233
default:
234-
iz.Throw("ext/deserialize/g", &token.Token{Source: "Pipefish builder"})
234+
iz.Throw("ext/deserialize/h", &token.Token{Source: "Pipefish builder"})
235235
return nil
236236

237237
}

source/lexer/lexer.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (l *Lexer) NextToken() token.Token {
126126
case '\'':
127127
r, ok := l.readRune()
128128
if !ok {
129-
return l.Throw("lex/quote/c")
129+
return l.Throw("lex/rune")
130130
}
131131
return l.NewToken(token.RUNE, r)
132132
case '.':
@@ -408,12 +408,12 @@ func (l *Lexer) readSnippet() string {
408408
}
409409
if langIndent == "" { // Then this is the first time around.
410410
if currentWhitespace == "" {
411-
l.Throw("lex/emdash/indent/a", l.NewToken(token.ILLEGAL, "lex/emdash/indent/a"))
411+
l.Throw("lex/emdash/indent/a", l.NewToken(token.ILLEGAL, "bad emdash"))
412412
return result
413413
}
414414
langIndent = currentWhitespace
415415
if langIndent == stackTop {
416-
l.Throw("lex/emdash/indent/b", l.NewToken(token.ILLEGAL, "lex/emdash/indent/b"))
416+
l.Throw("lex/emdash/indent/b", l.NewToken(token.ILLEGAL, "bad emdash"))
417417
return result
418418
}
419419
}
@@ -424,7 +424,7 @@ func (l *Lexer) readSnippet() string {
424424
return result
425425
}
426426
if !strings.HasPrefix(currentWhitespace, stackTop) && !(currentWhitespace == "\n") {
427-
l.Throw("lex/emdash/indent/c", l.NewToken(token.ILLEGAL, "lex/emdash/indent/c"))
427+
l.Throw("lex/emdash/indent/c", l.NewToken(token.ILLEGAL, "bad emdash"))
428428
return result
429429
}
430430
for l.peekChar() != '\n' && l.peekChar() != 0 {
@@ -454,22 +454,22 @@ func (l *Lexer) readGolang() string {
454454
}
455455
// We expect a brace or quotes after the golang keyword. (The quotes if it's in the import section, import golang "foo".)
456456
if l.peekChar() != '{' && l.peekChar() != '"' && l.peekChar() != '`' {
457-
l.Throw("lex/golang", l.NewToken(token.ILLEGAL, "lex/golang"))
457+
l.Throw("lex/golang", l.NewToken(token.ILLEGAL, "bad golang"))
458458
return ""
459459
}
460460
if l.peekChar() == '"' {
461461
l.readChar()
462462
s, ok := l.readFormattedString()
463463
if !ok {
464-
l.Throw("lex/quote/c", l.NewToken(token.ILLEGAL, "lex/quote/c"))
464+
l.Throw("lex/quote/c", l.NewToken(token.ILLEGAL, "bad quote"))
465465
}
466466
return s
467467
}
468468
if l.peekChar() == '`' {
469469
l.readChar()
470470
s, ok := l.readPlaintextString()
471471
if !ok {
472-
l.Throw("lex/quote/d", l.NewToken(token.ILLEGAL, "lex/quote/d"))
472+
l.Throw("lex/quote/d", l.NewToken(token.ILLEGAL, "bad quote"))
473473
}
474474
return s
475475
}

0 commit comments

Comments
 (0)