elvish/eval/exception.go
Qi Xiao ee81f0680c Use specific error types for parse, compile and eval.
Generic error types in util are ditched.
2017-01-28 14:39:52 +00:00

33 lines
581 B
Go

package eval
import (
"bytes"
"fmt"
"github.com/elves/elvish/util"
)
// Exception represents an elvish exception.
type Exception struct {
Cause error
Traceback *util.SourceContext
}
func (exc *Exception) Error() string {
return exc.Cause.Error()
}
func (exc *Exception) Pprint() string {
buf := new(bytes.Buffer)
// Error message
fmt.Fprintf(buf, "Exception: \033[31;1m%s\033[m\n", exc.Cause.Error())
buf.WriteString("Traceback:")
for tb := exc.Traceback; tb != nil; tb = tb.Next {
buf.WriteString("\n ")
tb.Pprint(buf, " ")
}
return buf.String()
}