aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/zclconf/go-cty-yaml/error.go
diff options
context:
space:
mode:
authorAlexandre Garand <alexandre.garand@fretlink.com>2019-08-09 15:59:15 +0200
committerAlexandre Garand <alexandre.garand@fretlink.com>2019-08-09 16:39:21 +0200
commit863486a6b71ed0e562a3965bed56465d007b1418 (patch)
treee93f6a687695af86d54237ec9f575d4ef104222d /vendor/github.com/zclconf/go-cty-yaml/error.go
parent49c1c7b4dc69ffb9ab52330e6dc52ccdd6351087 (diff)
downloadterraform-provider-statuscake-863486a6b71ed0e562a3965bed56465d007b1418.tar.gz
terraform-provider-statuscake-863486a6b71ed0e562a3965bed56465d007b1418.tar.zst
terraform-provider-statuscake-863486a6b71ed0e562a3965bed56465d007b1418.zip
update vendor and go.modadd_contact_groups
Diffstat (limited to 'vendor/github.com/zclconf/go-cty-yaml/error.go')
-rw-r--r--vendor/github.com/zclconf/go-cty-yaml/error.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty-yaml/error.go b/vendor/github.com/zclconf/go-cty-yaml/error.go
new file mode 100644
index 0000000..ae41c48
--- /dev/null
+++ b/vendor/github.com/zclconf/go-cty-yaml/error.go
@@ -0,0 +1,97 @@
1package yaml
2
3import (
4 "errors"
5 "fmt"
6)
7
8// Error is an error implementation used to report errors that correspond to
9// a particular position in an input buffer.
10type Error struct {
11 cause error
12 Line, Column int
13}
14
15func (e Error) Error() string {
16 return fmt.Sprintf("on line %d, column %d: %s", e.Line, e.Column, e.cause.Error())
17}
18
19// Cause is an implementation of the interface used by
20// github.com/pkg/errors.Cause, returning the underlying error without the
21// position information.
22func (e Error) Cause() error {
23 return e.cause
24}
25
26// WrappedErrors is an implementation of github.com/hashicorp/errwrap.Wrapper
27// returning the underlying error without the position information.
28func (e Error) WrappedErrors() []error {
29 return []error{e.cause}
30}
31
32func parserError(p *yaml_parser_t) error {
33 var cause error
34 if len(p.problem) > 0 {
35 cause = errors.New(p.problem)
36 } else {
37 cause = errors.New("invalid YAML syntax") // useless generic error, then
38 }
39
40 return parserErrorWrap(p, cause)
41}
42
43func parserErrorWrap(p *yaml_parser_t, cause error) error {
44 switch {
45 case p.problem_mark.line != 0:
46 line := p.problem_mark.line
47 column := p.problem_mark.column
48 // Scanner errors don't iterate line before returning error
49 if p.error == yaml_SCANNER_ERROR {
50 line++
51 column = 0
52 }
53 return Error{
54 cause: cause,
55 Line: line,
56 Column: column + 1,
57 }
58 case p.context_mark.line != 0:
59 return Error{
60 cause: cause,
61 Line: p.context_mark.line,
62 Column: p.context_mark.column + 1,
63 }
64 default:
65 return cause
66 }
67}
68
69func parserErrorf(p *yaml_parser_t, f string, vals ...interface{}) error {
70 return parserErrorWrap(p, fmt.Errorf(f, vals...))
71}
72
73func parseEventErrorWrap(evt *yaml_event_t, cause error) error {
74 if evt.start_mark.line == 0 {
75 // Event does not have a start mark, so we won't wrap the error at all
76 return cause
77 }
78 return Error{
79 cause: cause,
80 Line: evt.start_mark.line,
81 Column: evt.start_mark.column + 1,
82 }
83}
84
85func parseEventErrorf(evt *yaml_event_t, f string, vals ...interface{}) error {
86 return parseEventErrorWrap(evt, fmt.Errorf(f, vals...))
87}
88
89func emitterError(e *yaml_emitter_t) error {
90 var cause error
91 if len(e.problem) > 0 {
92 cause = errors.New(e.problem)
93 } else {
94 cause = errors.New("failed to write YAML token") // useless generic error, then
95 }
96 return cause
97}