tfdiags: show descriptions in diagnosticsAsError

Previously we were showing only the summaries when converting to a string
error, but HCL generates summaries that indicate only the _type_ of error,
expecting that the detail will give the details, and so we need to show
both in order to produce a useful error message.
This commit is contained in:
Martin Atkins 2017-10-13 14:11:42 -07:00
parent 6f7bc4f5d7
commit 094cdca688
1 changed files with 11 additions and 2 deletions

View File

@ -148,12 +148,21 @@ func (dae diagnosticsAsError) Error() string {
// there are no diagnostics in the list.
return "no errors"
case len(diags) == 1:
return diags[0].Description().Summary
desc := diags[0].Description()
if desc.Detail == "" {
return desc.Summary
}
return fmt.Sprintf("%s: %s", desc.Summary, desc.Detail)
default:
var ret bytes.Buffer
fmt.Fprintf(&ret, "%d problems:\n", len(diags))
for _, diag := range dae.Diagnostics {
fmt.Fprintf(&ret, "\n- %s", diag.Description().Summary)
desc := diag.Description()
if desc.Detail == "" {
fmt.Fprintf(&ret, "\n- %s", desc.Summary)
} else {
fmt.Fprintf(&ret, "\n- %s: %s", desc.Summary, desc.Detail)
}
}
return ret.String()
}