You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hclsyntax: Special error messages for EOF in certain contexts
For parts of the input that are delimited by start and end tokens, our
typical pattern is to keep scanning for items until we reach the end token,
or to generate an error if we encounter a token that isn't valid.
In some common examples of that we'll now treat TokenEOF as special and
report a different message about the element being unclosed, because it
seems common in practice for folks to leave off closing delimiters and
then be confused about HCL reporting a parse error at the end of the
file. Instead, we'll now report the error from the perspective of the
opening token(s) and describe that construct as "unclosed", because the
EOF range is generally less useful than any range that actually contains
some relevant characters.
This is not totally comprehensive for all cases, but covers some
situations that I've seen folks ask about, and some others that were
similar enough to those that it was easy to modify them in the same ways.
This does actually change one of the error ranges constrained by the
specification test suite, but in practice we're not actually using that
test suite to represent the "specification" for HCL, so it's better to
change the hypothetical specification to call for a better error reporting
behavior than to retain the old behavior just because we happened to
encoded in the (unfinished) test suite.
Detail: "There is no closing parenthesis for this function call before the end of the file. This may be caused by incorrect parethesis nesting elsewhere in this file.",
Detail: "There is no corresponding closing bracket before the end of the file. This may be caused by incorrect bracket nesting elsewhere in this file.",
1305
+
Subject: open.Range.Ptr(),
1306
+
})
1307
+
default:
1308
+
diags=append(diags, &hcl.Diagnostic{
1309
+
Severity: hcl.DiagError,
1310
+
Summary: "Missing item separator",
1311
+
Detail: "Expected a comma to mark the beginning of the next item.",
Copy file name to clipboardExpand all lines: hclsyntax/parser_template.go
+27-7Lines changed: 27 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -414,22 +414,42 @@ Token:
414
414
ifclose.Type!=TokenTemplateSeqEnd {
415
415
if!p.recovery {
416
416
switchclose.Type {
417
-
caseTokenColon:
417
+
caseTokenEOF:
418
418
diags=append(diags, &hcl.Diagnostic{
419
419
Severity: hcl.DiagError,
420
-
Summary: "Extra characters after interpolation expression",
421
-
Detail: "Template interpolation doesn't expect a colon at this location. Did you intend this to be a literal sequence to be processed as part of another language? If so, you can escape it by starting with \"$${\" instead of just \"${\".",
Detail: "There is no closing brace for this interpolation sequence before the end of the file. This might be caused by incorrect nesting inside the given expression.",
422
+
Subject: &startRange,
424
423
})
425
-
default:
424
+
caseTokenColon:
426
425
diags=append(diags, &hcl.Diagnostic{
427
426
Severity: hcl.DiagError,
428
427
Summary: "Extra characters after interpolation expression",
429
-
Detail: "Expected a closing brace to end the interpolation expression, but found extra characters.\n\nThis can happen when you include interpolation syntax for another language, such as shell scripting, but forget to escape the interpolation start token. If this is an embedded sequence for another language, escape it by starting with \"$${\" instead of just \"${\".",
428
+
Detail: "Template interpolation doesn't expect a colon at this location. Did you intend this to be a literal sequence to be processed as part of another language? If so, you can escape it by starting with \"$${\" instead of just \"${\".",
Detail: "There is no closing brace for this interpolation sequence before the end of the quoted template. This might be caused by incorrect nesting inside the given expression.",
442
+
Subject: &startRange,
443
+
})
444
+
} else {
445
+
diags=append(diags, &hcl.Diagnostic{
446
+
Severity: hcl.DiagError,
447
+
Summary: "Extra characters after interpolation expression",
448
+
Detail: "Expected a closing brace to end the interpolation expression, but found extra characters.\n\nThis can happen when you include interpolation syntax for another language, such as shell scripting, but forget to escape the interpolation start token. If this is an embedded sequence for another language, escape it by starting with \"$${\" instead of just \"${\".",
0 commit comments