-
Notifications
You must be signed in to change notification settings - Fork 42
Distribute error resources across packages with error codes and help URLs #223
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
Open
Copilot
wants to merge
16
commits into
main
Choose a base branch
from
copilot/refactor-error-exception-text
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,348
−125
Open
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
745ffec
Initial plan
Copilot 3fb85ff
Add error resources infrastructure and refactor authentication-msal e…
Copilot 35e5905
Refactor CosmosDB storage errors to use error resources
Copilot 076fb67
Refactor blob storage and Teams errors to use error resources
Copilot 6bbd39b
Refactor hosting, activity, and copilot studio errors to use error re…
Copilot 687c45c
Fix import order for __future__ annotations in activity module
Copilot a81d336
Fix circular import by using lazy imports in activity module
Copilot dd5d925
Add comprehensive documentation for error resources module
Copilot 7f33885
Fix code review feedback: move imports out of TYPE_CHECKING and remov…
Copilot 86ac5aa
Format all changed files with Black to fix build errors
Copilot 3d65776
Fix test failure by adding specific error for invalid CosmosDB key su…
Copilot b06f3b0
Distribute error resources to individual packages with updated ranges
Copilot 9d6e802
Update tests to reflect distributed error resources structure
Copilot b15c6bf
Fix error resource references and move imports to top of files
Copilot 74678c7
Complete fix for teams_info.py error resource references
Copilot 3c7ad49
Consolidate ErrorMessage class to hosting-core package
Copilot 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
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
14 changes: 14 additions & 0 deletions
14
libraries/microsoft-agents-activity/microsoft_agents/activity/errors/__init__.py
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,14 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """ | ||
| Error resources for Microsoft Agents Activity package. | ||
| """ | ||
|
|
||
| from .error_message import ErrorMessage | ||
| from .error_resources import ActivityErrorResources | ||
|
|
||
| # Singleton instance | ||
| activity_errors = ActivityErrorResources() | ||
cleemullins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| __all__ = ["ErrorMessage", "ActivityErrorResources", "activity_errors"] | ||
68 changes: 68 additions & 0 deletions
68
libraries/microsoft-agents-activity/microsoft_agents/activity/errors/error_message.py
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,68 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """ | ||
| ErrorMessage class for formatting error messages with error codes and help URLs. | ||
| """ | ||
|
|
||
|
|
||
| class ErrorMessage: | ||
| """ | ||
| Represents a formatted error message with error code and help URL. | ||
| This class formats error messages according to the Microsoft Agents SDK pattern: | ||
| - Original error message | ||
| - Error Code: [negative number] | ||
| - Help URL: https://aka.ms/M365AgentsErrorCodes/#anchor | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| message_template: str, | ||
| error_code: int, | ||
| help_url_anchor: str = "agentic-identity-with-the-m365-agents-sdk", | ||
| ): | ||
| """ | ||
| Initialize an ErrorMessage. | ||
| :param message_template: The error message template (may include format placeholders) | ||
| :type message_template: str | ||
| :param error_code: The error code (should be negative) | ||
| :type error_code: int | ||
| :param help_url_anchor: The anchor for the help URL (defaults to agentic identity) | ||
| :type help_url_anchor: str | ||
| """ | ||
| self.message_template = message_template | ||
| self.error_code = error_code | ||
| self.help_url_anchor = help_url_anchor | ||
| self.base_url = "https://aka.ms/M365AgentsErrorCodes" | ||
|
|
||
| def format(self, *args, **kwargs) -> str: | ||
| """ | ||
| Format the error message with the provided arguments. | ||
| :param args: Positional arguments for string formatting | ||
| :param kwargs: Keyword arguments for string formatting | ||
| :return: Formatted error message with error code and help URL | ||
| :rtype: str | ||
| """ | ||
| # Format the main message | ||
| if args or kwargs: | ||
| message = self.message_template.format(*args, **kwargs) | ||
| else: | ||
| message = self.message_template | ||
|
|
||
| # Append error code and help URL | ||
| return ( | ||
| f"{message}\n\n" | ||
| f"Error Code: {self.error_code}\n" | ||
| f"Help URL: {self.base_url}/#{self.help_url_anchor}" | ||
| ) | ||
|
|
||
| def __str__(self) -> str: | ||
| """Return the formatted error message without any arguments.""" | ||
| return self.format() | ||
|
|
||
| def __repr__(self) -> str: | ||
| """Return a representation of the ErrorMessage.""" | ||
| return f"ErrorMessage(code={self.error_code}, message='{self.message_template[:50]}...')" |
58 changes: 58 additions & 0 deletions
58
libraries/microsoft-agents-activity/microsoft_agents/activity/errors/error_resources.py
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,58 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """ | ||
| Activity error resources for Microsoft Agents SDK. | ||
| Error codes are in the range -64000 to -64999. | ||
| """ | ||
|
|
||
| from .error_message import ErrorMessage | ||
|
|
||
|
|
||
| class ActivityErrorResources: | ||
| """ | ||
| Error messages for activity operations. | ||
| Error codes are organized in the range -64000 to -64999. | ||
| """ | ||
|
|
||
| InvalidChannelIdType = ErrorMessage( | ||
| "Invalid type for channel_id: {0}. Expected ChannelId or str.", | ||
| -64000, | ||
| "activity-schema", | ||
| ) | ||
|
|
||
| ChannelIdProductInfoConflict = ErrorMessage( | ||
| "Conflict between channel_id.sub_channel and productInfo entity", | ||
| -64001, | ||
| "activity-schema", | ||
| ) | ||
|
|
||
| ChannelIdValueConflict = ErrorMessage( | ||
| "If value is provided, channel and sub_channel must be None", | ||
| -64002, | ||
| "activity-schema", | ||
| ) | ||
|
|
||
| ChannelIdValueMustBeNonEmpty = ErrorMessage( | ||
| "value must be a non empty string if provided", | ||
| -64003, | ||
| "activity-schema", | ||
| ) | ||
|
|
||
| InvalidFromPropertyType = ErrorMessage( | ||
| "Invalid type for from_property: {0}. Expected ChannelAccount or dict.", | ||
| -64004, | ||
| "activity-schema", | ||
| ) | ||
|
|
||
| InvalidRecipientType = ErrorMessage( | ||
| "Invalid type for recipient: {0}. Expected ChannelAccount or dict.", | ||
| -64005, | ||
| "activity-schema", | ||
| ) | ||
|
|
||
| def __init__(self): | ||
| """Initialize ActivityErrorResources.""" | ||
| pass |
14 changes: 14 additions & 0 deletions
14
...rosoft-agents-authentication-msal/microsoft_agents/authentication/msal/errors/__init__.py
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,14 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """ | ||
| Error resources for Microsoft Agents Authentication MSAL package. | ||
| """ | ||
|
|
||
| from .error_message import ErrorMessage | ||
| from .error_resources import AuthenticationErrorResources | ||
|
|
||
| # Singleton instance | ||
| authentication_errors = AuthenticationErrorResources() | ||
|
|
||
| __all__ = ["ErrorMessage", "AuthenticationErrorResources", "authentication_errors"] |
68 changes: 68 additions & 0 deletions
68
...t-agents-authentication-msal/microsoft_agents/authentication/msal/errors/error_message.py
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,68 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """ | ||
| ErrorMessage class for formatting error messages with error codes and help URLs. | ||
| """ | ||
|
|
||
|
|
||
| class ErrorMessage: | ||
| """ | ||
| Represents a formatted error message with error code and help URL. | ||
| This class formats error messages according to the Microsoft Agents SDK pattern: | ||
| - Original error message | ||
| - Error Code: [negative number] | ||
| - Help URL: https://aka.ms/M365AgentsErrorCodes/#anchor | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| message_template: str, | ||
| error_code: int, | ||
| help_url_anchor: str = "agentic-identity-with-the-m365-agents-sdk", | ||
| ): | ||
| """ | ||
| Initialize an ErrorMessage. | ||
| :param message_template: The error message template (may include format placeholders) | ||
| :type message_template: str | ||
| :param error_code: The error code (should be negative) | ||
| :type error_code: int | ||
| :param help_url_anchor: The anchor for the help URL (defaults to agentic identity) | ||
| :type help_url_anchor: str | ||
| """ | ||
| self.message_template = message_template | ||
| self.error_code = error_code | ||
| self.help_url_anchor = help_url_anchor | ||
| self.base_url = "https://aka.ms/M365AgentsErrorCodes" | ||
|
|
||
| def format(self, *args, **kwargs) -> str: | ||
| """ | ||
| Format the error message with the provided arguments. | ||
| :param args: Positional arguments for string formatting | ||
| :param kwargs: Keyword arguments for string formatting | ||
| :return: Formatted error message with error code and help URL | ||
| :rtype: str | ||
| """ | ||
| # Format the main message | ||
| if args or kwargs: | ||
| message = self.message_template.format(*args, **kwargs) | ||
| else: | ||
| message = self.message_template | ||
|
|
||
| # Append error code and help URL | ||
| return ( | ||
| f"{message}\n\n" | ||
| f"Error Code: {self.error_code}\n" | ||
| f"Help URL: {self.base_url}/#{self.help_url_anchor}" | ||
| ) | ||
|
|
||
| def __str__(self) -> str: | ||
| """Return the formatted error message without any arguments.""" | ||
| return self.format() | ||
|
|
||
| def __repr__(self) -> str: | ||
| """Return a representation of the ErrorMessage.""" | ||
| return f"ErrorMessage(code={self.error_code}, message='{self.message_template[:50]}...')" |
76 changes: 76 additions & 0 deletions
76
...agents-authentication-msal/microsoft_agents/authentication/msal/errors/error_resources.py
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,76 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """ | ||
| Authentication error resources for Microsoft Agents SDK. | ||
| Error codes are in the range -60000 to -60999. | ||
| """ | ||
|
|
||
| from .error_message import ErrorMessage | ||
|
|
||
|
|
||
| class AuthenticationErrorResources: | ||
| """ | ||
| Error messages for authentication operations. | ||
| Error codes are organized in the range -60000 to -60999. | ||
| """ | ||
|
|
||
| FailedToAcquireToken = ErrorMessage( | ||
| "Failed to acquire token. {0}", | ||
| -60012, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| InvalidInstanceUrl = ErrorMessage( | ||
| "Invalid instance URL", | ||
| -60013, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| OnBehalfOfFlowNotSupportedManagedIdentity = ErrorMessage( | ||
| "On-behalf-of flow is not supported with Managed Identity authentication.", | ||
| -60014, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| OnBehalfOfFlowNotSupportedAuthType = ErrorMessage( | ||
| "On-behalf-of flow is not supported with the current authentication type: {0}", | ||
| -60015, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| AuthenticationTypeNotSupported = ErrorMessage( | ||
| "Authentication type not supported", | ||
| -60016, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| AgentApplicationInstanceIdRequired = ErrorMessage( | ||
| "Agent application instance Id must be provided.", | ||
| -60017, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| FailedToAcquireAgenticInstanceToken = ErrorMessage( | ||
| "Failed to acquire agentic instance token or agent token for agent_app_instance_id {0}", | ||
| -60018, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| AgentApplicationInstanceIdAndUserIdRequired = ErrorMessage( | ||
| "Agent application instance Id and agentic user Id must be provided.", | ||
| -60019, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| FailedToAcquireInstanceOrAgentToken = ErrorMessage( | ||
| "Failed to acquire instance token or agent token for agent_app_instance_id {0} and agentic_user_id {1}", | ||
| -60020, | ||
| "agentic-identity-with-the-m365-agents-sdk", | ||
| ) | ||
|
|
||
| def __init__(self): | ||
| """Initialize AuthenticationErrorResources.""" | ||
| pass |
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.