-
Notifications
You must be signed in to change notification settings - Fork 626
DiagnosticTextWriter panics when writing a marked value #737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
wata727
added a commit
to wata727/hcl
that referenced
this issue
Mar 8, 2025
Fixes hashicorp#737 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 this does not take into account marked values and will cause a panic by `val.AsString()`, `val.LengthInt'()`, etc. This change prevents panics by always returning "(marked value)" for marked values in `valueStr`. Whether this is always appropriate is debatable, but it is better than the current situation, which causes panics.
wata727
added a commit
to wata727/hcl
that referenced
this issue
Mar 8, 2025
Fixes hashicorp#737 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 this does not take into account marked values and will cause a panic by `val.AsString()`, `val.LengthInt()`, etc. This change prevents panics by always returning "(marked value)" for marked values in `valueStr`. Whether this is always appropriate is debatable, but it is better than the current situation, which causes panics.
wata727
added a commit
to terraform-linters/tflint
that referenced
this issue
Mar 10, 2025
Fixes #2243 See also hashicorp/hcl#737 The `hcl.DiagnosticTextWriter` has an issue where it will panic when writing out a diagnostic that has an expression containing a marked value. TFLint can run into this issue when expanding the `for_each` meta-argument with a sensitive value. If the `for_each` is not iterable (it is not iterable if marked), a diagnostic containing the expression context of the `for_each` is created and written to stderr by the `DiagnosticTextWriter`. Hopefully this will be fixed in upstream, but here's a workaround to prevent the panic by excluding expression context from the diagnostic when the `for_each` is marked. By the way, other cases that include expression context in diagnostics do not have the same issue, so no action is required. - `for_each` is marked in dynamic blocks - The value is always unmarked, and non-iterable cases are rarer than those in meta-arguments - dynamic block labels - Dynamic block labels are rarely used in Terraform - `count` in meta-arguments - The value is always unmarked
wata727
added a commit
to wata727/hcl
that referenced
this issue
Mar 13, 2025
Fixes hashicorp#737 Follow up of hashicorp#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 best effort to be a general-purpose diagnostic writer, and can consider how to output them later if needed.
wata727
added a commit
to wata727/hcl
that referenced
this issue
Mar 13, 2025
Fixes hashicorp#737 Follow up of hashicorp#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, and can consider how to output them later if needed.
wata727
added a commit
to wata727/hcl
that referenced
this issue
Mar 13, 2025
Fixes hashicorp#737 Follow up of hashicorp#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.
wata727
added a commit
to terraform-linters/tflint
that referenced
this issue
Mar 28, 2025
Fixes #2243 See also hashicorp/hcl#737 The `hcl.DiagnosticTextWriter` has an issue where it will panic when writing out a diagnostic that has an expression containing a marked value. TFLint can run into this issue when expanding the `for_each` meta-argument with a sensitive value. If the `for_each` is not iterable (it is not iterable if marked), a diagnostic containing the expression context of the `for_each` is created and written to stderr by the `DiagnosticTextWriter`. Hopefully this will be fixed in upstream, but here's a workaround to prevent the panic by excluding expression context from the diagnostic when the `for_each` is marked. By the way, other cases that include expression context in diagnostics do not have the same issue, so no action is required. - `for_each` is marked in dynamic blocks - The value is always unmarked, and non-iterable cases are rarer than those in meta-arguments - dynamic block labels - Dynamic block labels are rarely used in Terraform - `count` in meta-arguments - The value is always unmarked
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
See also terraform-linters/tflint#2243
The
DiagnosticTextWriter
will panic when it writes a diagnostic whose expression has a marked value. The reproducible code is below:go.mod
The text was updated successfully, but these errors were encountered: