-
Notifications
You must be signed in to change notification settings - Fork 46
refactor: show error message #233
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
v-alexmoraru
wants to merge
8
commits into
microsoft:main
Choose a base branch
from
v-alexmoraru:dev/v-alexmoraru/show-error-message
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.
+102
−11
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
82b4898
Show error message explicitly
v-alexmoraru 2520c29
Merge branch 'main' into dev/v-alexmoraru/show-error-message
v-alexmoraru b79a245
Addresses comments + changelog
v-alexmoraru 07e0a11
Updates test assertion
v-alexmoraru 04998c9
Handles unset object case
v-alexmoraru 823ab90
Typo
v-alexmoraru d6411d5
Updates comment
v-alexmoraru bd351de
Comment suggestions
v-alexmoraru 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| kind: optimization | ||
| body: Shows explicit API error message | ||
| time: 2026-05-07T10:10:40.73557+03:00 | ||
| custom: | ||
| Author: v-alexmoraru | ||
| AuthorLink: https://github.com/v-alexmoraru | ||
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 |
|---|---|---|
|
|
@@ -8,13 +8,17 @@ | |
| # Default error constants - avoids circular imports | ||
| DEFAULT_ERROR_MESSAGE = "An error occurred while processing the operation" | ||
| DEFAULT_ERROR_CODE = "UnknownError" | ||
| NOT_SET = object() | ||
|
|
||
|
|
||
| class FabricCLIError(Exception): | ||
| def __init__(self, message=None, status_code=None): | ||
| # Use default values if not provided | ||
| def __init__(self, message=None, status_code=NOT_SET): | ||
| # message: values like (None, "") fall back to the default. | ||
| # status_code: default is applied only when omitted entirely; | ||
| # an explicit None is preserved (e.g. fallback paths that have no code). | ||
| message = message or DEFAULT_ERROR_MESSAGE | ||
| status_code = status_code or DEFAULT_ERROR_CODE | ||
| if status_code is NOT_SET: | ||
| status_code = DEFAULT_ERROR_CODE | ||
|
|
||
| super().__init__(message) | ||
| self.message = message.rstrip(".") | ||
|
|
@@ -78,12 +82,23 @@ def __init__(self, response_text): | |
| related_resource (dict): Details about the main related resource, if available. | ||
| request_id (str): The ID of the request associated with the error. | ||
| """ | ||
| response = self._parse_json_response(response_text) | ||
|
|
||
| message = response.get("message") | ||
| error_code = response.get("errorCode") | ||
| self.more_details: list[dict] = response.get("moreDetails", []) | ||
| self.request_id = response.get("requestId") | ||
| try: | ||
| response = json.loads(response_text) | ||
| if not isinstance(response, dict): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think response_text can be a string, not always an object. but Im not sure. worth checking it |
||
| raise ValueError("Unexpected JSON shape") | ||
|
v-alexmoraru marked this conversation as resolved.
|
||
| message = ( | ||
| response.get("message") | ||
| if response.get("message") is not None | ||
| else response_text | ||
| ) | ||
| error_code = response.get("errorCode") | ||
| self.more_details: list[dict] = response.get("moreDetails", []) | ||
| self.request_id = response.get("requestId") | ||
|
v-alexmoraru marked this conversation as resolved.
|
||
| except (json.JSONDecodeError, TypeError, ValueError): | ||
| message = response_text | ||
| error_code = None | ||
| self.more_details = [] | ||
| self.request_id = None | ||
|
v-alexmoraru marked this conversation as resolved.
|
||
|
|
||
| super().__init__(message, error_code) | ||
|
|
||
|
|
@@ -105,7 +120,10 @@ def formatted_message(self, verbose=False): | |
| else f"{base_message}\n<grey>{detailed_message}</grey>" | ||
| ) | ||
|
|
||
| return f"{final_message}\n<grey>∟ Request Id: {self.request_id}</grey>" | ||
| if self.request_id: | ||
| final_message += f"\n<grey>∟ Request Id: {self.request_id}</grey>" | ||
|
|
||
| return final_message | ||
|
|
||
|
|
||
| class OnelakeAPIError(FabricCLIError): | ||
|
|
||
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
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.