mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
ee81f0680c
Generic error types in util are ditched.
33 lines
581 B
Go
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()
|
|
}
|