Skip to content

Commit c916784

Browse files
committed
fix: narrow exception handling in _resolve_nested_stack_parameters
The helper caught bare Exception when resolving intrinsics in a nested-stack resource's Parameters property, silently swallowing any resolver bug (TypeError, AttributeError, KeyError from malformed state). A user would see incorrect template expansion with no signal. Now: - UnresolvableReferenceError / InvalidTemplateException continue (expected 'can't resolve at package time' cases — e.g. Ref to a sibling resource). - Any other exception is logged at DEBUG with traceback so --debug surfaces it; the value is still dropped so packaging proceeds. Matches the narrowing pattern applied to do_export's expansion call site in the previous commit.
1 parent 6956c10 commit c916784

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

samcli/lib/package/artifact_exporter.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def _resolve_nested_stack_parameters(nested_params: Dict, parent_parameter_value
7373
return {}
7474
# Local imports to preserve existing import ordering and avoid a cycle at load time.
7575
from samcli.lib.cfn_language_extensions.api import create_default_intrinsic_resolver
76+
from samcli.lib.cfn_language_extensions.exceptions import (
77+
InvalidTemplateException,
78+
UnresolvableReferenceError,
79+
)
7680
from samcli.lib.cfn_language_extensions.models import (
7781
ResolutionMode,
7882
TemplateProcessingContext,
@@ -89,7 +93,14 @@ def _resolve_nested_stack_parameters(nested_params: Dict, parent_parameter_value
8993
for name, value in nested_params.items():
9094
try:
9195
resolved_value = resolver.resolve_value(value)
92-
except Exception: # pragma: no cover - resolver raises only on malformed intrinsics
96+
except (UnresolvableReferenceError, InvalidTemplateException):
97+
# Expected: the nested-stack parameter references something the
98+
# resolver can't see at package time (e.g. a sibling resource).
99+
continue
100+
except Exception: # pylint: disable=broad-except
101+
# Unexpected — likely a SAM CLI bug. Log at debug with traceback so
102+
# --debug surfaces it; drop the value so packaging still proceeds.
103+
LOG.debug("Unexpected error resolving nested stack parameter %r; skipping", name, exc_info=True)
93104
continue
94105
# Drop values that still contain intrinsics (unresolvable at package time).
95106
if isinstance(resolved_value, dict) and len(resolved_value) == 1:

0 commit comments

Comments
 (0)