big overhaul of error-formatting, to get positions more consistently

fixes #2
This commit is contained in:
Ben Kraft
2021-04-15 17:01:46 -07:00
parent ade01c9280
commit 2c087c7821
18 changed files with 233 additions and 74 deletions
+3 -3
View File
@@ -1,7 +1,6 @@
package generate
import (
"fmt"
"go/types"
"strconv"
"strings"
@@ -45,7 +44,8 @@ func (g *generator) getRef(fullyQualifiedName string, addImport bool) (qualified
// confusing, why would you want it. But the empty interface,
// specifically, is useful.
if fullyQualifiedName != "interface{}" && types.Universe.Lookup(fullyQualifiedName) == nil {
return "", fmt.Errorf(
// TODO: pass in pos here
return "", errorf(nil,
`unknown name "%v"; expected a builtin or path/to/package.Name`, fullyQualifiedName)
}
return fullyQualifiedName, nil
@@ -60,7 +60,7 @@ func (g *generator) getRef(fullyQualifiedName string, addImport bool) (qualified
var ok bool
alias, ok = g.imports[pkgPath]
if !ok {
return "", fmt.Errorf(`no alias defined for package "%v"`, pkgPath)
return "", errorf(nil, `no alias defined for package "%v"`, pkgPath)
}
}
return alias + "." + localName, nil