fix(cloudformation): return ValidationError when JSON parse error has no location (#9213)

This commit is contained in:
Koushik Dutta authored and GitHub committed 2026-11-22 14:48:41 -04:00
1 parent 78ea3c90d9
commit 188371eabc
3 files changed
+38 -3

No files matched your search

@@ -48,14 +48,17 @@ final class CloudFormationTemplateParser {
return new CloudFormationYamlParser(objectMapper).parse(body);
} catch (YAMLException yamlError) {
if (jsonError != null && trimmed.startsWith("{") && trimmed.endsWith("}")) {
JsonLocation at = jsonError.getLocation();
throw new TemplateFormatException("JSON not well-formed. (line " + at.getLineNr()
+ ", column " + at.getColumnNr() + ")", jsonError);
throw new TemplateFormatException("JSON not well-formed." + position(jsonError), jsonError);
}
throw new TemplateFormatException("YAML not well-formed." + position(yamlError), yamlError);
}
}
private static String position(JsonProcessingException error) {
JsonLocation at = error.getLocation();
return at == null ? "" : " (line " + at.getLineNr() + ", column " + at.getColumnNr() + ")";
}
/** Where the YAML parser stopped, 1-based as CloudFormation counts; nothing for an error with no mark. */
private static String position(YAMLException error) {
if (!(error instanceof MarkedYAMLException marked)) {