diff options
author | appilon <apilon@hashicorp.com> | 2019-02-27 16:43:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-27 16:43:31 -0500 |
commit | 844b5a68d8af4791755b8f0ad293cc99f5959183 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/hcl2/hcl/diagnostic.go | |
parent | 303b299eeb6b06e939e35905e4b34cb410dd9dc3 (diff) | |
parent | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (diff) | |
download | terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.gz terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.zst terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.zip |
Merge pull request #27 from terraform-providers/go-modules-2019-02-22
[MODULES] Switch to Go Modules
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/diagnostic.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/hcl/diagnostic.go | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/diagnostic.go b/vendor/github.com/hashicorp/hcl2/hcl/diagnostic.go new file mode 100644 index 0000000..6ecf744 --- /dev/null +++ b/vendor/github.com/hashicorp/hcl2/hcl/diagnostic.go | |||
@@ -0,0 +1,103 @@ | |||
1 | package hcl | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | ) | ||
6 | |||
7 | // DiagnosticSeverity represents the severity of a diagnostic. | ||
8 | type DiagnosticSeverity int | ||
9 | |||
10 | const ( | ||
11 | // DiagInvalid is the invalid zero value of DiagnosticSeverity | ||
12 | DiagInvalid DiagnosticSeverity = iota | ||
13 | |||
14 | // DiagError indicates that the problem reported by a diagnostic prevents | ||
15 | // further progress in parsing and/or evaluating the subject. | ||
16 | DiagError | ||
17 | |||
18 | // DiagWarning indicates that the problem reported by a diagnostic warrants | ||
19 | // user attention but does not prevent further progress. It is most | ||
20 | // commonly used for showing deprecation notices. | ||
21 | DiagWarning | ||
22 | ) | ||
23 | |||
24 | // Diagnostic represents information to be presented to a user about an | ||
25 | // error or anomoly in parsing or evaluating configuration. | ||
26 | type Diagnostic struct { | ||
27 | Severity DiagnosticSeverity | ||
28 | |||
29 | // Summary and detail contain the English-language description of the | ||
30 | // problem. Summary is a terse description of the general problem and | ||
31 | // detail is a more elaborate, often-multi-sentence description of | ||
32 | // the probem and what might be done to solve it. | ||
33 | Summary string | ||
34 | Detail string | ||
35 | Subject *Range | ||
36 | Context *Range | ||
37 | } | ||
38 | |||
39 | // Diagnostics is a list of Diagnostic instances. | ||
40 | type Diagnostics []*Diagnostic | ||
41 | |||
42 | // error implementation, so that diagnostics can be returned via APIs | ||
43 | // that normally deal in vanilla Go errors. | ||
44 | // | ||
45 | // This presents only minimal context about the error, for compatibility | ||
46 | // with usual expectations about how errors will present as strings. | ||
47 | func (d *Diagnostic) Error() string { | ||
48 | return fmt.Sprintf("%s: %s; %s", d.Subject, d.Summary, d.Detail) | ||
49 | } | ||
50 | |||
51 | // error implementation, so that sets of diagnostics can be returned via | ||
52 | // APIs that normally deal in vanilla Go errors. | ||
53 | func (d Diagnostics) Error() string { | ||
54 | count := len(d) | ||
55 | switch { | ||
56 | case count == 0: | ||
57 | return "no diagnostics" | ||
58 | case count == 1: | ||
59 | return d[0].Error() | ||
60 | default: | ||
61 | return fmt.Sprintf("%s, and %d other diagnostic(s)", d[0].Error(), count-1) | ||
62 | } | ||
63 | } | ||
64 | |||
65 | // Append appends a new error to a Diagnostics and return the whole Diagnostics. | ||
66 | // | ||
67 | // This is provided as a convenience for returning from a function that | ||
68 | // collects and then returns a set of diagnostics: | ||
69 | // | ||
70 | // return nil, diags.Append(&hcl.Diagnostic{ ... }) | ||
71 | // | ||
72 | // Note that this modifies the array underlying the diagnostics slice, so | ||
73 | // must be used carefully within a single codepath. It is incorrect (and rude) | ||
74 | // to extend a diagnostics created by a different subsystem. | ||
75 | func (d Diagnostics) Append(diag *Diagnostic) Diagnostics { | ||
76 | return append(d, diag) | ||
77 | } | ||
78 | |||
79 | // Extend concatenates the given Diagnostics with the receiver and returns | ||
80 | // the whole new Diagnostics. | ||
81 | // | ||
82 | // This is similar to Append but accepts multiple diagnostics to add. It has | ||
83 | // all the same caveats and constraints. | ||
84 | func (d Diagnostics) Extend(diags Diagnostics) Diagnostics { | ||
85 | return append(d, diags...) | ||
86 | } | ||
87 | |||
88 | // HasErrors returns true if the receiver contains any diagnostics of | ||
89 | // severity DiagError. | ||
90 | func (d Diagnostics) HasErrors() bool { | ||
91 | for _, diag := range d { | ||
92 | if diag.Severity == DiagError { | ||
93 | return true | ||
94 | } | ||
95 | } | ||
96 | return false | ||
97 | } | ||
98 | |||
99 | // A DiagnosticWriter emits diagnostics somehow. | ||
100 | type DiagnosticWriter interface { | ||
101 | WriteDiagnostic(*Diagnostic) error | ||
102 | WriteDiagnostics(Diagnostics) error | ||
103 | } | ||