From 946eda3f3cf5066b41e1bab4442f5d7ddea79d72 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 12 Mar 2020 10:53:44 -0700 Subject: [PATCH] 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. --- configs/module.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/configs/module.go b/configs/module.go index fe6c8f4235..b6c50b75c8 100644 --- a/configs/module.go +++ b/configs/module.go @@ -183,18 +183,17 @@ func (m *Module) appendFile(file *File) hcl.Diagnostics { if reqd.Source.SourceStr != "" { var sourceDiags tfdiags.Diagnostics fqn, sourceDiags = addrs.ParseProviderSourceString(reqd.Source.SourceStr) - if sourceDiags.HasErrors() { - for i := range sourceDiags { - if sourceDiags[i].Severity() == tfdiags.Error { - diags = append(diags, &hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Invalid provider source string", - Detail: sourceDiags[i].Description().Detail, - Subject: &reqd.Source.DeclRange, - }) - } + hclDiags := sourceDiags.ToHCL() + // The diagnostics from ParseProviderSourceString don't contain + // source location information because it has no context to compute + // them from, and so we'll add those in quickly here before we + // return. + for _, diag := range hclDiags { + if diag.Subject == nil { + diag.Subject = reqd.Source.DeclRange.Ptr() } } + diags = append(diags, hclDiags...) } else { fqn = addrs.NewLegacyProvider(reqd.Name) }