Skip to content

Fix #4270: Emit BCP180 error for nested getSecret() instead of crashing#19258

Open
jiangmingzhe wants to merge 1 commit intoAzure:mainfrom
jiangmingzhe:mingzhejiang/unhandled-exception-getsecret
Open

Fix #4270: Emit BCP180 error for nested getSecret() instead of crashing#19258
jiangmingzhe wants to merge 1 commit intoAzure:mainfrom
jiangmingzhe:mingzhejiang/unhandled-exception-getsecret

Conversation

@jiangmingzhe
Copy link
Member

@jiangmingzhe jiangmingzhe commented Mar 23, 2026

Previously, when getSecret() was used inside nested objects in module parameters (e.g., params: { config: { secret: kv.getSecret('x') } }), the compiler would crash with NotImplementedException during emit instead of validating the placement during semantic analysis.

This fix adds validation logic in FunctionPlacementValidatorVisitor to detect when getSecret() is nested inside object structures by:

  • Walking up the syntax tree from the function call
  • Counting ObjectSyntax nodes between the property and params boundary
  • Allowing 0 levels of nesting for params, 1 for extensionConfigs
  • Emitting BCP180 diagnostic for invalid nested cases

The ARM template schema only supports KeyVault references at the top parameter level (as { reference: {...} }), not nested within value objects, so this validation prevents generating invalid ARM templates.

Added comprehensive test coverage:

  • Nested objects at various depths (2-3 levels)
  • Nested objects in loops and ternary expressions
  • Nested objects inside arrays
  • All existing tests continue to pass (valid cases unaffected)

Fixes #4270

Description

Example Usage

Checklist

Microsoft Reviewers: Open in CodeFlow

…rashing

Previously, when getSecret() was used inside nested objects in module
parameters (e.g., params: { config: { secret: kv.getSecret('x') } }),
the compiler would crash with NotImplementedException during emit
instead of validating the placement during semantic analysis.

This fix adds validation logic in FunctionPlacementValidatorVisitor to
detect when getSecret() is nested inside object structures by:
- Walking up the syntax tree from the function call
- Counting ObjectSyntax nodes between the property and params boundary
- Allowing 0 levels of nesting for params, 1 for extensionConfigs
- Emitting BCP180 diagnostic for invalid nested cases

The ARM template schema only supports KeyVault references at the top
parameter level (as { reference: {...} }), not nested within value
objects, so this validation prevents generating invalid ARM templates.

Added comprehensive test coverage:
- Nested objects at various depths (2-3 levels)
- Nested objects in loops and ternary expressions
- Nested objects inside arrays
- All existing tests continue to pass (valid cases unaffected)

Fixes Azure#4270
@jiangmingzhe jiangmingzhe force-pushed the mingzhejiang/unhandled-exception-getsecret branch from 43521bf to 1d9f672 Compare March 24, 2026 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: ability to use GetSecret() in a conditional way

1 participant