github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/hcl2/diagnostics.go (about) 1 package hcl2 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/hcl/v2" 7 "github.com/hashicorp/hcl/v2/hclsyntax" 8 "github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/model" 9 ) 10 11 func errorf(subject hcl.Range, f string, args ...interface{}) *hcl.Diagnostic { 12 return diagf(hcl.DiagError, subject, f, args...) 13 } 14 15 func diagf(severity hcl.DiagnosticSeverity, subject hcl.Range, f string, args ...interface{}) *hcl.Diagnostic { 16 message := fmt.Sprintf(f, args...) 17 return &hcl.Diagnostic{ 18 Severity: severity, 19 Summary: message, 20 Detail: message, 21 Subject: &subject, 22 } 23 } 24 25 func labelsErrorf(block *hclsyntax.Block, f string, args ...interface{}) *hcl.Diagnostic { 26 startRange := block.LabelRanges[0] 27 28 diagRange := hcl.Range{ 29 Filename: startRange.Filename, 30 Start: startRange.Start, 31 End: block.LabelRanges[len(block.LabelRanges)-1].End, 32 } 33 return errorf(diagRange, f, args...) 34 } 35 36 func malformedToken(token string, sourceRange hcl.Range) *hcl.Diagnostic { 37 return errorf(sourceRange, "malformed token '%v': expected 'pkg:module:member'", token) 38 } 39 40 func unknownPackage(pkg string, tokenRange hcl.Range) *hcl.Diagnostic { 41 return errorf(tokenRange, "unknown package '%s'", pkg) 42 } 43 44 func unknownResourceType(token string, tokenRange hcl.Range) *hcl.Diagnostic { 45 return errorf(tokenRange, "unknown resource type '%s'", token) 46 } 47 48 func unknownFunction(token string, tokenRange hcl.Range) *hcl.Diagnostic { 49 return errorf(tokenRange, "unknown function '%s'", token) 50 } 51 52 func unsupportedBlock(blockType string, typeRange hcl.Range) *hcl.Diagnostic { 53 return errorf(typeRange, "unsupported block of type '%v'", blockType) 54 } 55 56 func unsupportedAttribute(attrName string, nameRange hcl.Range) *hcl.Diagnostic { 57 return errorf(nameRange, "unsupported attribute '%v'", attrName) 58 } 59 60 func missingRequiredAttribute(attrName string, missingRange hcl.Range) *hcl.Diagnostic { 61 return errorf(missingRange, "missing required attribute '%v'", attrName) 62 } 63 64 func tokenMustBeStringLiteral(tokenExpr model.Expression) *hcl.Diagnostic { 65 return errorf(tokenExpr.SyntaxNode().Range(), "invoke token must be a string literal") 66 } 67 68 func duplicateBlock(blockType string, typeRange hcl.Range) *hcl.Diagnostic { 69 return errorf(typeRange, "duplicate block of type '%v'", blockType) 70 }