github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/tfdiags/diagnostic.go (about) 1 package tfdiags 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/hcl/v2" 7 ) 8 9 type Diagnostic interface { 10 Severity() Severity 11 Description() Description 12 Source() Source 13 14 // FromExpr returns the expression-related context for the diagnostic, if 15 // available. Returns nil if the diagnostic is not related to an 16 // expression evaluation. 17 FromExpr() *FromExpr 18 19 // ExtraInfo returns the raw extra information value. This is a low-level 20 // API which requires some work on the part of the caller to properly 21 // access associated information, so in most cases it'll be more convienient 22 // to use the package-level ExtraInfo function to try to unpack a particular 23 // specialized interface from this value. 24 ExtraInfo() interface{} 25 } 26 27 type Severity rune 28 29 //go:generate go run golang.org/x/tools/cmd/stringer -type=Severity 30 31 const ( 32 Error Severity = 'E' 33 Warning Severity = 'W' 34 ) 35 36 // ToHCL converts a Severity to the equivalent HCL diagnostic severity. 37 func (s Severity) ToHCL() hcl.DiagnosticSeverity { 38 switch s { 39 case Warning: 40 return hcl.DiagWarning 41 case Error: 42 return hcl.DiagError 43 default: 44 // The above should always be exhaustive for all of the valid 45 // Severity values in this package. 46 panic(fmt.Sprintf("unknown diagnostic severity %s", s)) 47 } 48 } 49 50 type Description struct { 51 Address string 52 Summary string 53 Detail string 54 } 55 56 type Source struct { 57 Subject *SourceRange 58 Context *SourceRange 59 } 60 61 type FromExpr struct { 62 Expression hcl.Expression 63 EvalContext *hcl.EvalContext 64 }