-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
53 lines (41 loc) · 1.17 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package pars
import (
"errors"
"fmt"
)
var errNoChildren = errors.New("result does not have children")
// Error is a generic parser error.
type Error struct {
what string
pos Position
}
// NewError creates a new Error.
func NewError(what string, pos Position) error { return Error{what, pos} }
// Error satisfies the error interface.
func (e Error) Error() string { return fmt.Sprintf("%s at %s", e.what, e.pos) }
// NestedError is a nested error type.
type NestedError struct {
name string
err error
}
// NewNestedError creates a new NestedError.
func NewNestedError(name string, err error) error {
return NestedError{name, err}
}
// Error satisfies the error interface.
func (e NestedError) Error() string {
return fmt.Sprintf("in %s:\n%s", e.name, e.err)
}
// Unwrap returns the internal error value.
func (e NestedError) Unwrap() error { return e.err }
// BoundError is an error bound to a parser.
type BoundError struct {
err error
pos Position
}
// Error satisfies the error interface.
func (e BoundError) Error() string {
return fmt.Sprintf("%s at %s", e.err, e.pos)
}
// Unwrap returns the internal error value.
func (e BoundError) Unwrap() error { return e.err }