Skip to content

Fix TeamsTemplatesPolicy error handling to prevent false drift (Fixes…#6903

Open
Shiva210Jyoti wants to merge 3 commits intomicrosoft:Devfrom
Shiva210Jyoti:fix/teams-templatespolicy-erroraction
Open

Fix TeamsTemplatesPolicy error handling to prevent false drift (Fixes…#6903
Shiva210Jyoti wants to merge 3 commits intomicrosoft:Devfrom
Shiva210Jyoti:fix/teams-templatespolicy-erroraction

Conversation

@Shiva210Jyoti
Copy link

Fixes #6899

Ensures TeamsTemplatesPolicy cmdlet failures are terminating by replacing SilentlyContinue and implicit non-terminating errors with -ErrorAction Stop for Get-CsTeamsTemplatePermissionPolicy and Get-CsTeamTemplateList.

This prevents partial state evaluation when Teams APIs return malformed responses, eliminating false-positive drift on HiddenTemplates.

Changes are minimal and localized to MSFT_TeamsTemplatesPolicy.psm1.

@ricmestre
Copy link
Contributor

What if I want to create a policy that doesn't exist yet? With your diff it will throw an error and the resource won't be created.

Did you actually tested this?

@FabienTschanz
Copy link
Collaborator

FabienTschanz commented Feb 12, 2026

The -ErrorAction Stop on Get-CsTeamTemplateList is correct in my opinion, and also the one in the Export-TargetResource. However, as @ricmestre mentioned, the first instance must not be like that, otherwise it will never work for non-existing instances, which is a very valid scenario. This cannot be fixed on an individual resource level but must rather be regarded as a matter affecting all resources and thus treated as such using better error handling.

@ricmestre
Copy link
Contributor

Correct, with that changed the rest of the diff is fine by me

@SNikalaichyk
Copy link
Contributor

Agree with @ricmestre.

It is important to handle the actual exception thrown by Get-CsTeamsTemplatePermissionPolicy to not re-throw the Object not found one and to return valid drift. The actual exception type and message needs to be confirmed first.

@NikCharlebois
Copy link
Collaborator

@Shiva210Jyoti can you update your PR accordingly? Thanks

@Shiva210Jyoti
Copy link
Author

@microsoft-github-policy-service agree

@Shiva210Jyoti
Copy link
Author

Thanks for the feedback everyone.

Updated the implementation so that only the first Get-CsTeamsTemplatePermissionPolicy call is wrapped in targeted try/catch logic. It now returns $nullReturn for NotFound scenarios while keeping other failures terminating, which allows creation of new policies while still preventing partial-state evaluation.

Confirmed behavior:
• Non-existing policy → returns Absent state (no error)
• API failure / malformed response → terminating error

Other cmdlet calls retain -ErrorAction Stop as suggested.

Ready for re-review.

@FabienTschanz
Copy link
Collaborator

@Shiva210Jyoti Please add an entry to the changelog. Thank you.

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.

TeamsTemplatesPolicy: Error Handling Issues

5 participants