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 e2086ce commit fcd4329
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 21 deletions.
5 changes: 3 additions & 2 deletions source/checkerr.pf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import

const

// Things that have the right format to be error codes but aren't.
// 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).
FALSE_POSITIVES = set(`"database/sql"`, `"encoding/json"`, `"math/rand"`, `"net/http"`,
.. `"os/exec"`, `"path/filepath"`, `"html/template"`)
.. `"os/exec"`, `"path/filepath"`, `"html/template"`, `"vm/user"`)

cmd

Expand Down
2 changes: 1 addition & 1 deletion source/compiler/compfcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func (cp *Compiler) seekFunctionCall(b *bindle) AlternateType {
// It could have a Golang body.
if F.HasGo {
cp.cmP("Emitting Go function call.", b.tok)
convErrorLoc := cp.reserveError("golang/conv/x", b.tok)
convErrorLoc := cp.reserveError("golang/conv", b.tok)
args := append([]uint32{b.outLoc, convErrorLoc, F.GoNumber}, b.valLocs...)
cp.Emit(vm.Gofn, args...)
if len(branch.Node.Fn.NameRets) == 0 {
Expand Down
73 changes: 61 additions & 12 deletions source/err/errorfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,34 +1195,63 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"golang/conv/a": {
"golang/compile": {
Message: func(tok *token.Token, args ...any) string {
return "failed to convert golang values."
return "failed to compile Go"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This error should not occur."
return "A Pipefish function written in Go has failed to compile at initialization time."
},
},

"golang/conv/b": {
"golang/concrete/a": {
Message: func(tok *token.Token, args ...any) string {
return "failed to convert golang values."
return "abstract type in signature of golang function"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This error should not occur."
return "Only concrete types can appear in the signature of a golang function because " +
"how would you convert an abstract type to Go?"
},
},

"golang/concrete/b": {
Message: func(tok *token.Token, args ...any) string {
return "abstract type in signature of golang function"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Only concrete types can appear in the signature of a golang function because " +
"how would you convert an abstract type to Go?"
},
},

"golang/conv/c": {
"golang/conv": {
Message: func(tok *token.Token, args ...any) string {
return "failed to convert golang values."
return "failed to convert golang values"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This error should not occur."
},
},

"golang/open": {
"golang/create": {
Message: func(tok *token.Token, args ...any) string {
return "failed to create .go file with error " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "For some reason Pipefish was literally unable to write the file to disc."
},
},

"golang/open/a": {
Message: func(tok *token.Token, args ...any) string {
return "failed to open Go\n\nError was '" + args[0].(string) + "'"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "A Pipefish function written in Go has failed to open at initialization time."
},
},

"golang/open/b": {
Message: func(tok *token.Token, args ...any) string {
return "failed to open Go\n\nError was '" + args[0].(string) + "'"
},
Expand Down Expand Up @@ -1260,12 +1289,21 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"golang/type": {
"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"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This is because the author of Pipefish hasn't gotten around to it yet."
return "Not all types can be passed to Go. This isn't one of them."
},
},

"golang/type/b": {
Message: func(tok *token.Token, args ...any) string {
return "can't pass value of type " + emph(args[0]) + " to Go"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Not all types can be passed to Go. This isn't one of them."
},
},

Expand All @@ -1274,7 +1312,18 @@ var ErrorCreatorMap = map[string]ErrorCreator{
return "can't pass value of type " + emph(args[0]) + " to Go"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This is because the author of Pipefish hasn't gotten around to it yet."
return "Not all types can be passed to Go. This isn't one of them."
},
},

"golang/variadic": {
Message: func(tok *token.Token, args ...any) string {
return "non-final parameter of golang function can't be variadic"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Such signatures don't make sense in Go and in fact since a golang " +
"function can only have a vanilla sig, it wouldn't make sense in" +
"Pipefish either."
},
},

Expand Down
8 changes: 4 additions & 4 deletions source/initializer/gogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ var cloneConv = map[values.ValueType]string{
// This produces the names of the field types in the struct declarations generated for the Go code.
func (iz *initializer) convertFieldTypeFromPfToGo(aT values.AbstractType) string {
if aT.Len() > 1 {
iz.Throw("golang/type/concrete", INTEROP_TOKEN)
iz.Throw("golang/concrete/a", INTEROP_TOKEN)
return ""
}
typeNumber := aT.Types[0]
typeName := iz.cp.Vm.ConcreteTypeInfo[typeNumber].GetName(vm.DEFAULT)
goType, ok := getGoType(typeName)
if !ok {
iz.Throw("golang/type/illegal", INTEROP_TOKEN)
iz.Throw("golang/type/c", INTEROP_TOKEN, typeName)
return ""
}
return goType
Expand All @@ -128,7 +128,7 @@ func (iz *initializer) generateGoFunctionCode(sb *strings.Builder, function *ast
case 1:
goType, ok := getGoType(function.NameRets[0].VarType)
if !ok {
iz.Throw("golang/param/a",function.Tok, function.NameRets[0].VarType)
iz.Throw("golang/type/a",function.Tok, function.NameRets[0].VarType)
}
fmt.Fprint(sb, goType, " ")
default:
Expand All @@ -143,7 +143,7 @@ func (iz *initializer) printSig(sb *strings.Builder, sig ast.StringSig, tok toke
for _, param := range sig {
goType, ok := getGoType(param.VarType)
if !ok {
iz.Throw("golang/param/b", &tok, param.VarType)
iz.Throw("golang/type/b", &tok, param.VarType)
}
fmt.Fprint(sb, sep, param.VarName)
if param.VarName != "" { // In which case it would be a return signature.
Expand Down
4 changes: 2 additions & 2 deletions source/initializer/gohandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (iz *initializer) makeNewSoFile(source string, newTime int64) *plugin.Plugi
iz.cmG("Creating goFile with filepath '" + goFile + "'\n\n", source)
file, err := os.Create(goFile)
if err != nil {
iz.Throw("golang/create", sourceToken, err.Error(), goFile)
iz.Throw("golang/create", sourceToken, err.Error())
return nil
}
file.WriteString(sb.String())
Expand Down Expand Up @@ -272,7 +272,7 @@ func (iz *initializer) transitivelyCloseTypes(userDefinedTypes dtypes.Set[string
for structName := range structsToCheck {
for _, fieldType := range iz.cp.TypeInfoNow(structName).(vm.StructType).AbstractStructFields {
if fieldType.Len() != 1 {
iz.Throw("golang/type/concrete/a", INTEROP_TOKEN, iz.cp.Vm.DescribeAbstractType(fieldType, vm.LITERAL))
iz.Throw("golang/concrete/b", INTEROP_TOKEN, iz.cp.Vm.DescribeAbstractType(fieldType, vm.LITERAL))
}
typeOfField := iz.cp.GetTypeNameFromNumber(fieldType.Types[0])
switch fieldData := iz.cp.TypeInfoNow(typeOfField).(type) {
Expand Down

0 comments on commit fcd4329

Please sign in to comment.