package value
import "fmt"
type Error struct {
Value Value
Inner error
}
type TypeError struct {
Value Value
Expected Type
}
func (te TypeError) Error() string {
return fmt.Sprintf("expected %s, got %s", te.Expected, te.Value.Type())
}
func (de Error) Error() string { return de.Inner.Error() }
type MissingKeyError struct {
Value Value
Missing string
}
func (mke MissingKeyError) Error() string {
return fmt.Sprintf("key %q does not exist", mke.Missing)
}
type ElementError struct {
Value Value
Index int
Inner error
}
func (ee ElementError) Error() string { return ee.Inner.Error() }
type FieldError struct {
Value Value
Field string
Inner error
}
func (fe FieldError) Error() string { return fe.Inner.Error() }
type ArgError struct {
Function Value
Argument Value
Index int
Inner error
}
func (ae ArgError) Error() string { return ae.Inner.Error() }
func WalkError(err error, f func(err error)) bool {
var foundOne bool
nextError := err
for nextError != nil {
switch ne := nextError.(type) {
case Error:
f(nextError)
nextError = ne.Inner
foundOne = true
case TypeError:
f(nextError)
nextError = nil
foundOne = true
case MissingKeyError:
f(nextError)
nextError = nil
foundOne = true
case ElementError:
f(nextError)
nextError = ne.Inner
foundOne = true
case FieldError:
f(nextError)
nextError = ne.Inner
foundOne = true
case ArgError:
f(nextError)
nextError = ne.Inner
foundOne = true
default:
nextError = nil
}
}
return foundOne
}