Skip to content

Commit 467621e

Browse files
committed
Skip marked values when writing diagnostics
Fixes #737 Follow up of #738 When the `DiagnosticTextWriter` writes out a diagnostic, if the diagnostic has an Expression and EvalContext, it will also write out the evaluation context in which the diagnostic occurred. The `cty.Value` of the variable relevant to the expression will be rendered as a string by `valueStr`, but calls to `AsString` or `LengthInt` here will panic on marked values. It is not clear how HCL should represent such marks, so we skip the marked values from the additional context as a general-purpose diagnostic writer.
1 parent 5c140ce commit 467621e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

diagnostic_text.go

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ func (w *diagnosticTextWriter) WriteDiagnostic(diag *Diagnostic) error {
170170
continue
171171
case val.IsNull():
172172
stmts = append(stmts, fmt.Sprintf("%s set to null", traversalStr))
173+
case val.IsMarked():
174+
// Skip the marked values as it is not clear here how they should be rendered.
175+
continue
173176
default:
174177
stmts = append(stmts, fmt.Sprintf("%s as %s", traversalStr, w.valueStr(val)))
175178
}

diagnostic_text_test.go

+22-3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,21 @@ Did you mean "pizzetta"?
157157
Name: "boz",
158158
},
159159
},
160+
{
161+
TraverseRoot{
162+
Name: "marked",
163+
},
164+
},
165+
{
166+
TraverseRoot{
167+
Name: "null",
168+
},
169+
},
170+
{
171+
TraverseRoot{
172+
Name: "unknown",
173+
},
174+
},
160175
},
161176
},
162177
EvalContext: &EvalContext{
@@ -169,8 +184,11 @@ Did you mean "pizzetta"?
169184
"bar": cty.ObjectVal(map[string]cty.Value{
170185
"baz": cty.ListValEmpty(cty.String),
171186
}),
172-
"boz": cty.NumberIntVal(5),
173-
"unused": cty.True,
187+
"boz": cty.NumberIntVal(5),
188+
"marked": cty.StringVal("marked").Mark("x"),
189+
"null": cty.NullVal(cty.String),
190+
"unknown": cty.UnknownVal(cty.String),
191+
"unused": cty.True,
174192
},
175193
},
176194
},
@@ -181,7 +199,8 @@ Did you mean "pizzetta"?
181199
182200
with bar.baz as empty list of string,
183201
boz as 5,
184-
foo as "foo value".
202+
foo as "foo value",
203+
null set to null.
185204
186205
This diagnostic includes an expression
187206
and an evalcontext.

0 commit comments

Comments
 (0)