-
Notifications
You must be signed in to change notification settings - Fork 335
Add azdext.Run lifecycle and structured extension error transport
#6835
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
caa9fdc
Add azdext.Run lifecycle and structured extension error transport
JeffreyCA 0c46263
Rename fields
JeffreyCA a942040
Address comments
JeffreyCA 095b537
Address comments
JeffreyCA 6737c54
Modern go cleanup
JeffreyCA 242f333
Enhance error handling and UX for extension errors; improve error mes…
JeffreyCA e229672
Update comment
JeffreyCA a328e97
Add back newline and include `WithAccessToken` in `Run`
JeffreyCA 2795906
Report errors via standard gRPC
JeffreyCA c35b320
Reuse existing error fields and update `ErrorKey` to conditionally pr…
JeffreyCA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/pkg/azdext" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/extensions" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestExtensionReportedError(t *testing.T) { | ||
| t.Run("NoErrorReported", func(t *testing.T) { | ||
| ext := &extensions.Extension{Id: "test.ext"} | ||
| require.Nil(t, ext.GetReportedError()) | ||
| }) | ||
|
|
||
| t.Run("LocalErrorReported", func(t *testing.T) { | ||
| ext := &extensions.Extension{Id: "test.ext"} | ||
| localErr := &azdext.LocalError{ | ||
| Message: "invalid config", | ||
| Code: "invalid_config", | ||
| Category: azdext.LocalErrorCategoryValidation, | ||
| Suggestion: "Fix the config file", | ||
| } | ||
| ext.SetReportedError(localErr) | ||
|
|
||
| reported := ext.GetReportedError() | ||
| require.NotNil(t, reported) | ||
|
|
||
| var gotLocal *azdext.LocalError | ||
| require.True(t, errors.As(reported, &gotLocal)) | ||
| require.Equal(t, "invalid_config", gotLocal.Code) | ||
| require.Equal(t, azdext.LocalErrorCategoryValidation, gotLocal.Category) | ||
| require.Equal(t, "Fix the config file", gotLocal.Suggestion) | ||
| }) | ||
|
|
||
| t.Run("ServiceErrorReported", func(t *testing.T) { | ||
| ext := &extensions.Extension{Id: "test.ext"} | ||
| svcErr := &azdext.ServiceError{ | ||
| Message: "not found", | ||
| ErrorCode: "NotFound", | ||
| StatusCode: 404, | ||
| ServiceName: "test.service.com", | ||
| } | ||
| ext.SetReportedError(svcErr) | ||
|
|
||
| reported := ext.GetReportedError() | ||
| require.NotNil(t, reported) | ||
|
|
||
| var gotSvc *azdext.ServiceError | ||
| require.True(t, errors.As(reported, &gotSvc)) | ||
| require.Equal(t, "NotFound", gotSvc.ErrorCode) | ||
| require.Equal(t, 404, gotSvc.StatusCode) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,47 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| syntax = "proto3"; | ||
|
|
||
| package azdext; | ||
|
|
||
| option go_package = "github.com/azure/azure-dev/cli/azd/pkg/azdext"; | ||
|
|
||
| // ErrorOrigin indicates where an error originated from. | ||
| // This helps with telemetry categorization and error handling strategies. | ||
| enum ErrorOrigin { | ||
| ERROR_ORIGIN_UNSPECIFIED = 0; // Default/unknown origin | ||
| ERROR_ORIGIN_LOCAL = 1; // Local errors: config, filesystem, auth state, validation, etc. | ||
| ERROR_ORIGIN_SERVICE = 2; // HTTP/gRPC upstream service errors | ||
| ERROR_ORIGIN_TOOL = 3; // Subprocess, plugin, or external tool errors | ||
| } | ||
|
|
||
| // ServiceErrorDetail contains structured error information from an HTTP/gRPC service. | ||
| // Used when ErrorOrigin is ERROR_ORIGIN_SERVICE. | ||
| message ServiceErrorDetail { | ||
| string error_code = 1; // Error code from the service (e.g., "Conflict", "NotFound", "RateLimitExceeded") | ||
| int32 status_code = 2; // HTTP status code (e.g., 409, 404, 500) | ||
| string service_name = 3; // Service host/name for telemetry (e.g., "ai.azure.com", "management.azure.com") | ||
| } | ||
|
|
||
| // ExtensionError is a unified error message that can represent errors from different sources. | ||
| // It provides structured error information for telemetry and error handling. | ||
| message ExtensionError { | ||
| string message = 2; // Human-readable error message | ||
| string details = 3; // Additional error details | ||
| ErrorOrigin origin = 4; // Where the error originated from | ||
|
|
||
| // Source-specific structured details. Only one should be set based on origin. | ||
| oneof source { | ||
| ServiceErrorDetail service_error = 10; | ||
| // ToolErrorDetail tool_error = 11; // Reserved for future use | ||
| // LocalErrorDetail local_error = 12; // Reserved for future use | ||
| } | ||
| } | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| syntax = "proto3"; | ||
|
|
||
| package azdext; | ||
|
|
||
| option go_package = "github.com/azure/azure-dev/cli/azd/pkg/azdext"; | ||
|
|
||
| // ErrorOrigin indicates where an error originated from. | ||
| // This helps with telemetry categorization and error handling strategies. | ||
| enum ErrorOrigin { | ||
| ERROR_ORIGIN_UNSPECIFIED = 0; // Default/unknown origin | ||
| ERROR_ORIGIN_LOCAL = 1; // Local errors: config, filesystem, auth state, validation, etc. | ||
| ERROR_ORIGIN_SERVICE = 2; // HTTP/gRPC upstream service errors | ||
| ERROR_ORIGIN_TOOL = 3; // Subprocess, plugin, or external tool errors | ||
| } | ||
|
|
||
| // ServiceErrorDetail contains structured error information from an HTTP/gRPC service. | ||
| // Used when ErrorOrigin is ERROR_ORIGIN_SERVICE. | ||
| message ServiceErrorDetail { | ||
| string error_code = 1; // Error code from the service (e.g., "Conflict", "NotFound", "RateLimitExceeded") | ||
| int32 status_code = 2; // HTTP status code (e.g., 409, 404, 500) | ||
| string service_name = 3; // Service host/name for telemetry (e.g., "ai.azure.com", "management.azure.com") | ||
| } | ||
|
|
||
| // LocalErrorDetail contains structured error information for local/validation failures. | ||
| // Used when ErrorOrigin is ERROR_ORIGIN_LOCAL. | ||
| message LocalErrorDetail { | ||
| string code = 1; // Extension-defined error code (e.g., "invalid_config") | ||
| string category = 2; // Error category (e.g., "user", "validation", "dependency", "internal") | ||
| } | ||
|
|
||
| // ExtensionError is a unified error message that can represent errors from different sources. | ||
| // It provides structured error information for telemetry and error handling. | ||
| message ExtensionError { | ||
| reserved 1, 3; // Reserved for future use; do not reuse. | ||
| string message = 2; // Human-readable error message | ||
| ErrorOrigin origin = 4; // Where the error originated from | ||
| string suggestion = 5; // Optional user-facing suggestion for resolving the error | ||
|
|
||
| // Source-specific structured details. Only one should be set based on origin. | ||
| oneof source { | ||
| ServiceErrorDetail service_error = 10; | ||
| LocalErrorDetail local_error = 11; | ||
| // ToolErrorDetail tool_error = 12; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.