interp: show backtrace with error

This should make it much easier to figure out why and where an error
happens at package initialization time.
This commit is contained in:
Ayke van Laethem
2020-03-28 20:46:09 +01:00
committed by Ron Evans
parent 2501602b4f
commit cc4a4c755f
6 changed files with 70 additions and 73 deletions
+13 -13
View File
@@ -658,22 +658,22 @@ func usage() {
// to limitations in the LLVM bindings.
func printCompilerError(logln func(...interface{}), err error) {
switch err := err.(type) {
case *interp.Unsupported:
// hit an unknown/unsupported instruction
logln("#", err.ImportPath)
msg := "unsupported instruction during init evaluation:"
if err.Pos.String() != "" {
msg = err.Pos.String() + " " + msg
}
logln(msg)
err.Inst.Dump()
logln()
case types.Error, scanner.Error:
logln(err)
case interp.Error:
case *interp.Error:
logln("#", err.ImportPath)
for _, err := range err.Errs {
logln(err)
logln(err.Error())
if !err.Inst.IsNil() {
err.Inst.Dump()
logln()
}
if len(err.Traceback) > 0 {
logln("\ntraceback:")
for _, line := range err.Traceback {
logln(line.Pos.String() + ":")
line.Inst.Dump()
logln()
}
}
case loader.Errors:
logln("#", err.Pkg.ImportPath)