Skip to content

Commit

Permalink
Better error message for Ref AWS::NoValue at Properties (#3565)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Aug 4, 2024
1 parent 0e9e807 commit c1bac05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/cfnlint/rules/resources/properties/Properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any

from cfnlint.helpers import FUNCTIONS, is_function
from cfnlint.jsonschema import ValidationResult, Validator
from cfnlint.jsonschema import ValidationError, ValidationResult, Validator
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema
from cfnlint.schema.manager import PROVIDER_SCHEMA_MANAGER

Expand Down Expand Up @@ -87,7 +87,14 @@ def validate(
properties = instance.get("Properties", {})
fn_k, fn_v = is_function(properties)
if fn_k == "Ref" and fn_v == "AWS::NoValue":
properties = {}
yield ValidationError(
# Expected an object, received {"Ref":"AWS::NoValue"}
message=f"{properties!r} is not of type object",
path=deque(["Properties", fn_k]),
rule=self.child_rules.get(self.rule_set.get("type")), # type: ignore
validator="type",
)
return

for regions, schema in PROVIDER_SCHEMA_MANAGER.get_resource_schemas_by_regions(
t, validator.context.regions
Expand Down
12 changes: 6 additions & 6 deletions test/unit/rules/resources/properties/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def rule():
],
),
(
"Valid type but no required fields",
"Invalid with Ref AWS::NoValue",
{"Type": "MyType", "Properties": {"Ref": "AWS::NoValue"}},
[(["us-east-1"], Schema({"typeName": "MyType", "required": ["Name"]}))],
[],
[
ValidationError(
"'Name' is a required property",
validator="required",
path=deque(["Properties"]),
schema_path=deque(["required"]),
"{'Ref': 'AWS::NoValue'} is not of type object",
validator="type",
path=deque(["Properties", "Ref"]),
rule=None,
)
],
),
Expand Down

0 comments on commit c1bac05

Please sign in to comment.