diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/hashicorp/terraform/internal/earlyconfig/diagnostics.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/internal/earlyconfig/diagnostics.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/internal/earlyconfig/diagnostics.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/internal/earlyconfig/diagnostics.go b/vendor/github.com/hashicorp/terraform/internal/earlyconfig/diagnostics.go new file mode 100644 index 0000000..9b2fd7f --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/internal/earlyconfig/diagnostics.go | |||
@@ -0,0 +1,78 @@ | |||
1 | package earlyconfig | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | |||
6 | "github.com/hashicorp/terraform-config-inspect/tfconfig" | ||
7 | "github.com/hashicorp/terraform/tfdiags" | ||
8 | ) | ||
9 | |||
10 | func wrapDiagnostics(diags tfconfig.Diagnostics) tfdiags.Diagnostics { | ||
11 | ret := make(tfdiags.Diagnostics, len(diags)) | ||
12 | for i, diag := range diags { | ||
13 | ret[i] = wrapDiagnostic(diag) | ||
14 | } | ||
15 | return ret | ||
16 | } | ||
17 | |||
18 | func wrapDiagnostic(diag tfconfig.Diagnostic) tfdiags.Diagnostic { | ||
19 | return wrappedDiagnostic{ | ||
20 | d: diag, | ||
21 | } | ||
22 | } | ||
23 | |||
24 | type wrappedDiagnostic struct { | ||
25 | d tfconfig.Diagnostic | ||
26 | } | ||
27 | |||
28 | func (d wrappedDiagnostic) Severity() tfdiags.Severity { | ||
29 | switch d.d.Severity { | ||
30 | case tfconfig.DiagError: | ||
31 | return tfdiags.Error | ||
32 | case tfconfig.DiagWarning: | ||
33 | return tfdiags.Warning | ||
34 | default: | ||
35 | // Should never happen since there are no other severities | ||
36 | return 0 | ||
37 | } | ||
38 | } | ||
39 | |||
40 | func (d wrappedDiagnostic) Description() tfdiags.Description { | ||
41 | // Since the inspect library doesn't produce precise source locations, | ||
42 | // we include the position information as part of the error message text. | ||
43 | // See the comment inside method "Source" for more information. | ||
44 | switch { | ||
45 | case d.d.Pos == nil: | ||
46 | return tfdiags.Description{ | ||
47 | Summary: d.d.Summary, | ||
48 | Detail: d.d.Detail, | ||
49 | } | ||
50 | case d.d.Detail != "": | ||
51 | return tfdiags.Description{ | ||
52 | Summary: d.d.Summary, | ||
53 | Detail: fmt.Sprintf("On %s line %d: %s", d.d.Pos.Filename, d.d.Pos.Line, d.d.Detail), | ||
54 | } | ||
55 | default: | ||
56 | return tfdiags.Description{ | ||
57 | Summary: fmt.Sprintf("%s (on %s line %d)", d.d.Summary, d.d.Pos.Filename, d.d.Pos.Line), | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | func (d wrappedDiagnostic) Source() tfdiags.Source { | ||
63 | // Since the inspect library is constrained by the lowest common denominator | ||
64 | // between legacy HCL and modern HCL, it only returns ranges at whole-line | ||
65 | // granularity, and that isn't sufficient to populate a tfdiags.Source | ||
66 | // and so we'll just omit ranges altogether and include the line number in | ||
67 | // the Description text. | ||
68 | // | ||
69 | // Callers that want to return nicer errors should consider reacting to | ||
70 | // earlyconfig errors by attempting a follow-up parse with the normal | ||
71 | // config loader, which can produce more precise source location | ||
72 | // information. | ||
73 | return tfdiags.Source{} | ||
74 | } | ||
75 | |||
76 | func (d wrappedDiagnostic) FromExpr() *tfdiags.FromExpr { | ||
77 | return nil | ||
78 | } | ||