-
Notifications
You must be signed in to change notification settings - Fork 14
Fix Error Handling Issues: Recursive Retry Loops and Diagnostic Control Flow #809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
To finish the task you have to
Changie InstructionsCreate only one change log entry. Do not run the changie tool multiple times. changie new --kind <kind_key> --body "<description>" --custom Issue=<issue_number> Where:
|
To finish the task you have to
Changie InstructionsCreate only one change log entry. Do not run the changie tool multiple times. changie new --kind <kind_key> --body "<description>" --custom Issue=<issue_number> Where:
|
Added changie entry documenting fixes for recursive retry loops, missing return statements, and improved error wrapping in environment services. Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR prevents infinite retry loops, adds missing early returns after diagnostic errors, and enriches error messages with context.
- Introduces retry-limited helper methods (maxRetries=10) across environment and managed-environment clients
- Adds
return
statements immediately afterresp.Diagnostics.AddError
to stop invalid-state execution - Wraps raw errors with
fmt.Errorf(...%w)
for better debugging in environment settings and templates
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
internal/services/managed_environment/api_managed_environment.go | Added enable/disableManagedEnvironmentWithRetry with retry limits |
internal/services/environment/api_environment.go | Added retry‐limited helpers for Delete/Create/Update/Modify operations |
internal/services/environment_settings/api_environment_settings.go | Wrapped Api.Execute errors with context |
internal/services/environment_templates/api_environment_templates.go | Wrapped execute and unmarshal errors with context |
internal/services/environment/resource_environment.go | Inserted missing return after AddError calls |
.changes/unreleased/fixed-20250604-133404.yaml | Added changelog entry documenting the fixes |
Comments suppressed due to low confidence (2)
internal/services/environment_templates/api_environment_templates.go:41
- [nitpick] The error message doesn’t include the
loc
parameter passed to the function; consider includingloc
(e.g.,...for location %s: %w
, loc) to improve diagnostic context.
return templates, fmt.Errorf("failed to execute API request for environment templates: %w", err)
internal/services/environment/api_environment.go:307
- Add a unit test covering the retry exhaustion path to confirm the function returns the expected error once
maxRetries
is reached.
if retryCount >= maxRetries {
internal/services/managed_environment/api_managed_environment.go
Outdated
Show resolved
Hide resolved
@copilot The maxRetries constant is duplicated across multiple retry functions; consider defining a shared package-level constant or configuration to avoid repeating this magic number. |
…RY_COUNT Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Fixed the duplicated maxRetries constant by introducing a shared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the available code search results for this PR, there are no matches showing a variable being assigned or initialized to MAX_RETRY_COUNT and then decremented in a retry loop. The search for direct usage, assignment, or loop constructs referencing MAX_RETRY_COUNT (such as for i := 0; i < MAX_RETRY_COUNT) did not return any results.
This means that, in the changes introduced by this PR, MAX_RETRY_COUNT was defined as a constant, but there is no code where a variable is set to MAX_RETRY_COUNT and then decremented in a retry loop.
You're absolutely correct. The retry implementation uses an incrementing counter pattern (starting at 0, incrementing on each retry, compared against MAX_RETRY_COUNT) rather than a traditional decrementing loop pattern. The retry logic checks |
Co-authored-by: eduardodfmex <15805460+eduardodfmex@users.noreply.github.com>
@copilot run |
Completed unit test validation successfully. All tests for the modified services (environment and managed_environment) are passing. There are 2 failing tests in the API client for managed identity authentication, but these are pre-existing infrastructure issues unrelated to the error handling fixes - they fail due to connection timeouts to Azure managed identity endpoints in the test environment. The linting passed with no issues, documentation was regenerated successfully, and the changelog entry was already created in commit 3c70358. |
This PR addresses critical error handling issues in the Power Platform provider that could lead to infinite loops and data corruption.
Issues Fixed
Issue 1: Recursive Retry Loops (Medium Severity)
Problem: Several methods in environment services used unbounded recursion for retry logic, which could result in infinite loops if APIs consistently returned errors.
Files affected:
internal/services/environment/api_environment.go
internal/services/managed_environment/api_managed_environment.go
Methods fixed:
DeleteEnvironment
CreateEnvironment
UpdateEnvironment
UpdateEnvironmentAiFeatures
ModifyEnvironmentType
EnableManagedEnvironment
DisableManagedEnvironment
Solution: Replaced recursive calls with retry-limited versions that prevent infinite loops by implementing a maximum retry count of 10 attempts.
Before:
After:
Issue 2: Missing Return Statements After AddError (High Severity)
Problem: Functions continued execution after calling
resp.Diagnostics.AddError()
, potentially operating on invalid data and causing data corruption.File affected:
internal/services/environment/resource_environment.go
Solution: Added missing
return
statements immediately afterAddError
calls to prevent continued execution with invalid state.Before:
After:
Issue 3: Non-idiomatic Error Wrapping (Medium Severity)
Problem: API errors were returned directly without contextual information, making debugging difficult.
Files affected:
internal/services/environment_settings/api_environment_settings.go
internal/services/environment_templates/api_environment_templates.go
Solution: Added proper error wrapping with context using
fmt.Errorf
with%w
verb.Before:
After:
Testing
Impact
Fixes #808.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.