DecodeFile is a wrapper around Decode that first reads the given filename from disk. See the Decode documentation for more information.
(filename string, ctx *hcl.EvalContext, target interface{})
| 86 | // DecodeFile is a wrapper around Decode that first reads the given filename |
| 87 | // from disk. See the Decode documentation for more information. |
| 88 | func DecodeFile(filename string, ctx *hcl.EvalContext, target interface{}) error { |
| 89 | src, err := os.ReadFile(filename) |
| 90 | if err != nil { |
| 91 | if os.IsNotExist(err) { |
| 92 | return hcl.Diagnostics{ |
| 93 | { |
| 94 | Severity: hcl.DiagError, |
| 95 | Summary: "Configuration file not found", |
| 96 | Detail: fmt.Sprintf("The configuration file %s does not exist.", filename), |
| 97 | }, |
| 98 | } |
| 99 | } |
| 100 | return hcl.Diagnostics{ |
| 101 | { |
| 102 | Severity: hcl.DiagError, |
| 103 | Summary: "Failed to read configuration", |
| 104 | Detail: fmt.Sprintf("Can't read %s: %s.", filename, err), |
| 105 | }, |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return Decode(filename, src, ctx, target) |
| 110 | } |