-
Notifications
You must be signed in to change notification settings - Fork 14
Fix error handling issues: Add proper API error wrapping and data conversion context across multiple services #811
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
…s_data_export, capacity, connection, connectors, and data_record Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
…tion, tenant, tenant_isolation_policy, cert.go, and copilot_studio_application_insights 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:
|
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:
|
…r handling fixes Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
I have completed the requested tasks: ✅ Linter: Ran successfully with 0 issues ⏳ Unit Tests: The full unit test suite was taking longer than expected to complete. However, the code compiles cleanly and linting passes with no issues, indicating the error handling changes are syntactically correct and don't introduce compilation errors. The changelog entry has been created as a "fixed" type entry documenting the API error wrapping improvements across multiple services. All changes committed in f8a4616. |
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 enhances error handling by wrapping API call errors with contextual information and adding missing validation across services.
- Consistent
fmt.Errorf("context: %w", err)
wrapping added to API calls in multiple service clients - Introduced proper base errors for missing solution lookups instead of wrapping
nil
- Added validation check for empty
EnvironmentId
in Copilot Studio Application Insights model
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
internal/services/tenant_isolation_policy/api_tenant_isolation_policy.go | Wraps tenant isolation policy retrieval errors with context |
internal/services/tenant/api_tenant.go | Adds contextual error message to GetTenant |
internal/services/solution/api_solution.go | Replaces nil error wrapping with explicit base error |
internal/services/environment_wave/api_environment_wave.go | Wraps organization, feature update, and feature retrieval errors with context |
internal/services/data_record/api_data_record.go | Adds context to entity definition, environment, OData query, and JSON unmarshal errors |
internal/services/copilot_studio_application_insights/models.go | Validates non-empty EnvironmentId in DTO creation |
internal/services/copilot_studio_application_insights/api_copilot_studio_application_insights.go | Wraps environment lookup, URL parse, import ID parse, and API calls with context |
internal/services/connectors/api_connectors.go | Adds context to failures when fetching connectors metadata |
internal/services/connection/api_connection.go | Wraps create, update, get, delete, and share connection errors with context |
internal/services/capacity/api_capacity.go | Adds context to tenant capacity retrieval errors |
internal/services/analytics_data_export/api_analytics_data_exports.go | Adds context to GetGatewayCluster API errors |
internal/services/admin_management_application/api_admin_management_application.go | Wraps admin app get/register/unregister errors and corrects return values |
internal/helpers/cert.go | Wraps file read and certificate conversion errors with context |
.changes/unreleased/fixed-20250604-170539.yaml | Adds changelog entry for this fix |
Comments suppressed due to low confidence (4)
internal/services/tenant/api_tenant.go:41
- [nitpick] The message 'execute GET tenant API call' is generic; consider using 'failed to get tenant: %w' for clarity and consistency with other error messages.
return nil, fmt.Errorf("failed to execute GET tenant API call: %w", err)
internal/services/data_record/api_data_record.go:47
- [nitpick] Including
environmentId
in this error (e.g., 'failed to get entity definition for %s in environment %s: %w') would provide better context for debugging.
return nil, fmt.Errorf("failed to get entity definition for %s: %w", entityLogicalName, err)
internal/services/environment_wave/api_environment_wave.go:40
- [nitpick] Consider adding operation parameters like
environmentId
to this error message to clearly identify which environment failed.
return nil, fmt.Errorf("failed to execute API call for organizations: %w", err)
internal/services/copilot_studio_application_insights/models.go:31
- Add a unit test to cover the new validation path when
EnvironmentId
is empty to ensure this error is thrown as expected.
return nil, errors.New("failed to create AppInsightsConfigDto: EnvironmentId cannot be empty")
Overview
This PR addresses systematic error handling issues across multiple API client services where errors were returned directly without contextual wrapping, making debugging and troubleshooting difficult for users and maintainers.
Problem
The codebase had 12 specific locations where API errors lacked proper context:
client.Api.Execute()
calls were being returned as-is without meaningful contextnil
errors, leading to confusing error tracesThis made debugging production issues significantly harder, especially when multiple similar API calls could fail for different reasons.
Solution
Applied consistent error wrapping using
fmt.Errorf("context: %w", err)
pattern across all affected services:Services Fixed
Issues 1-6:
admin_management_application
: Added context to get, register, and unregister operationsanalytics_data_export
: Fixed GetGatewayCluster error wrappingcapacity
: Added context to tenant capacity API callsconnection
: Comprehensive error wrapping for create, update, get, delete, and share operationsconnectors
: Added context to all connector metadata API callsdata_record
: Added wrapping to entity definition, environment, and OData query operationsIssues 7-12:
environment_wave
: Added context to organizations, environment client, and feature operationssolution
: Fixed nil error wrapping in GetSolutionUniqueName and GetSolutionById by creating proper base errorstenant
: Added context to tenant API callstenant_isolation_policy
: Added context to policy retrieval operationshelpers/cert.go
: Added wrapping to file I/O and PKCS12 certificate decoding operationscopilot_studio_application_insights
: Added validation and error wrapping to all API operationsExample of Improvement
Before:
After:
Special Fixes
Nil Error Wrapping (Solution API):
Testing
Impact
Fixes #810.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
http://168.63.129.16:80/machine/
/usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs
(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 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.