From 094cdca688c514882d53761e8c3dfe4d9d65023e Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 13 Oct 2017 14:11:42 -0700 Subject: [PATCH] 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. --- tfdiags/diagnostics.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tfdiags/diagnostics.go b/tfdiags/diagnostics.go index 3542857848..667ba8096d 100644 --- a/tfdiags/diagnostics.go +++ b/tfdiags/diagnostics.go @@ -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() }