mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
configs: Return diagnostics (almost) directly from ParseProviderSourceString
This function can already produce suitable diagnostic messages which we'd like to preserve, but it cannot produce source location information, and so we'll amend the diagnostics to include that on the way out while retaining all of the other values in the diagnostics.
This commit is contained in:
parent
a851566c56
commit
946eda3f3c
@ -183,18 +183,17 @@ func (m *Module) appendFile(file *File) hcl.Diagnostics {
|
|||||||
if reqd.Source.SourceStr != "" {
|
if reqd.Source.SourceStr != "" {
|
||||||
var sourceDiags tfdiags.Diagnostics
|
var sourceDiags tfdiags.Diagnostics
|
||||||
fqn, sourceDiags = addrs.ParseProviderSourceString(reqd.Source.SourceStr)
|
fqn, sourceDiags = addrs.ParseProviderSourceString(reqd.Source.SourceStr)
|
||||||
if sourceDiags.HasErrors() {
|
hclDiags := sourceDiags.ToHCL()
|
||||||
for i := range sourceDiags {
|
// The diagnostics from ParseProviderSourceString don't contain
|
||||||
if sourceDiags[i].Severity() == tfdiags.Error {
|
// source location information because it has no context to compute
|
||||||
diags = append(diags, &hcl.Diagnostic{
|
// them from, and so we'll add those in quickly here before we
|
||||||
Severity: hcl.DiagError,
|
// return.
|
||||||
Summary: "Invalid provider source string",
|
for _, diag := range hclDiags {
|
||||||
Detail: sourceDiags[i].Description().Detail,
|
if diag.Subject == nil {
|
||||||
Subject: &reqd.Source.DeclRange,
|
diag.Subject = reqd.Source.DeclRange.Ptr()
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
diags = append(diags, hclDiags...)
|
||||||
} else {
|
} else {
|
||||||
fqn = addrs.NewLegacyProvider(reqd.Name)
|
fqn = addrs.NewLegacyProvider(reqd.Name)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user