github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/object/error.go (about) 1 package object 2 3 import "fmt" 4 5 type StackTrace struct { 6 Source string 7 Line int 8 Signature string 9 IsTailCall bool 10 } 11 12 type RuntimeError struct { 13 RawValue Value 14 Level int 15 Traceback []*StackTrace 16 } 17 18 func NewRuntimeError(msg string) *RuntimeError { 19 return &RuntimeError{RawValue: String(msg), Level: 1} 20 } 21 22 func (err *RuntimeError) Value() Value { 23 if msg, ok := err.RawValue.(String); ok { 24 if 0 < err.Level && err.Level < len(err.Traceback) { 25 tb := err.Traceback[err.Level] 26 if tb.Source != "[Go]" { 27 return String(fmt.Sprintf("%s:%d: %s", tb.Source, tb.Line, msg)) 28 } 29 } 30 } 31 return err.RawValue 32 } 33 34 func (err *RuntimeError) Error() string { 35 return fmt.Sprintf("runtime: %s", Repr(err.Value())) 36 }