Skip to content

Commit c1bac05

Browse files
authored
Better error message for Ref AWS::NoValue at Properties (#3565)
1 parent 0e9e807 commit c1bac05

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/cfnlint/rules/resources/properties/Properties.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any
99

1010
from cfnlint.helpers import FUNCTIONS, is_function
11-
from cfnlint.jsonschema import ValidationResult, Validator
11+
from cfnlint.jsonschema import ValidationError, ValidationResult, Validator
1212
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema
1313
from cfnlint.schema.manager import PROVIDER_SCHEMA_MANAGER
1414

@@ -87,7 +87,14 @@ def validate(
8787
properties = instance.get("Properties", {})
8888
fn_k, fn_v = is_function(properties)
8989
if fn_k == "Ref" and fn_v == "AWS::NoValue":
90-
properties = {}
90+
yield ValidationError(
91+
# Expected an object, received {"Ref":"AWS::NoValue"}
92+
message=f"{properties!r} is not of type object",
93+
path=deque(["Properties", fn_k]),
94+
rule=self.child_rules.get(self.rule_set.get("type")), # type: ignore
95+
validator="type",
96+
)
97+
return
9198

9299
for regions, schema in PROVIDER_SCHEMA_MANAGER.get_resource_schemas_by_regions(
93100
t, validator.context.regions

test/unit/rules/resources/properties/test_properties.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ def rule():
5454
],
5555
),
5656
(
57-
"Valid type but no required fields",
57+
"Invalid with Ref AWS::NoValue",
5858
{"Type": "MyType", "Properties": {"Ref": "AWS::NoValue"}},
59-
[(["us-east-1"], Schema({"typeName": "MyType", "required": ["Name"]}))],
59+
[],
6060
[
6161
ValidationError(
62-
"'Name' is a required property",
63-
validator="required",
64-
path=deque(["Properties"]),
65-
schema_path=deque(["required"]),
62+
"{'Ref': 'AWS::NoValue'} is not of type object",
63+
validator="type",
64+
path=deque(["Properties", "Ref"]),
65+
rule=None,
6666
)
6767
],
6868
),

0 commit comments

Comments
 (0)