Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/optimization-20260507-101040.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: optimization
body: Shows explicit API error message
Comment thread
v-alexmoraru marked this conversation as resolved.
time: 2026-05-07T10:10:40.73557+03:00
custom:
Author: v-alexmoraru
AuthorLink: https://github.com/v-alexmoraru
38 changes: 28 additions & 10 deletions src/fabric_cli/core/fab_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
v-alexmoraru marked this conversation as resolved.

super().__init__(message)
self.message = message.rstrip(".")
Expand Down Expand Up @@ -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):
Comment thread
v-alexmoraru marked this conversation as resolved.
raise ValueError("Unexpected JSON shape")
Comment thread
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")
Comment thread
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
Comment thread
v-alexmoraru marked this conversation as resolved.

super().__init__(message, error_code)

Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion src/fabric_cli/utils/fab_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def print_output_error(
)
return
case "text":
_print_error_format_text(error.formatted_message(), command)
is_debug = fab_state_config.get_config(fab_constant.FAB_DEBUG_ENABLED) == "true"
_print_error_format_text(error.formatted_message(verbose=is_debug), command)
return
case _:
raise FabricCLIError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- ms-fabric-cli/1.5.0 (None; Linux/6.6.87.2-microsoft-standard-WSL2; Python/3.12.11)
- ms-fabric-cli/1.6.1 (None; Linux/6.12.76-linuxkit; Python/3.12.11)
method: GET
uri: https://api.fabric.microsoft.com/v1/workspaces
response:
Expand All @@ -26,15 +26,15 @@ interactions:
Content-Encoding:
- gzip
Content-Length:
- '2308'
- '2588'
Content-Type:
- application/json; charset=utf-8
Date:
- Thu, 23 Apr 2026 12:40:16 GMT
- Wed, 20 May 2026 08:33:44 GMT
Pragma:
- no-cache
RequestId:
- 7b546c98-4533-4288-81c6-7ca6074cf2f4
- 5c301c19-c565-4b04-97c4-df1fcdc930cb
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
Expand All @@ -60,7 +60,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- ms-fabric-cli/1.5.0 (None; Linux/6.6.87.2-microsoft-standard-WSL2; Python/3.12.11)
- ms-fabric-cli/1.6.1 (None; Linux/6.12.76-linuxkit; Python/3.12.11)
method: GET
uri: https://api.fabric.microsoft.com/v1/workspaces
response:
Expand All @@ -75,15 +75,15 @@ interactions:
Content-Encoding:
- gzip
Content-Length:
- '2308'
- '2588'
Content-Type:
- application/json; charset=utf-8
Date:
- Thu, 23 Apr 2026 12:40:17 GMT
- Wed, 20 May 2026 08:33:45 GMT
Pragma:
- no-cache
RequestId:
- 7af9bc26-9f8c-44ff-8a34-10f53017f117
- 5481d892-0423-47f8-bd7c-ec6baa2e818b
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
Expand All @@ -109,7 +109,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- ms-fabric-cli/1.5.0 (None; Linux/6.6.87.2-microsoft-standard-WSL2; Python/3.12.11)
- ms-fabric-cli/1.6.1 (None; Linux/6.12.76-linuxkit; Python/3.12.11)
method: GET
uri: https://api.fabric.microsoft.com/v1/capacities
response:
Expand All @@ -125,15 +125,15 @@ interactions:
Content-Encoding:
- gzip
Content-Length:
- '425'
- '426'
Content-Type:
- application/json; charset=utf-8
Date:
- Thu, 23 Apr 2026 12:40:20 GMT
- Wed, 20 May 2026 08:33:51 GMT
Pragma:
- no-cache
RequestId:
- d78e7414-567e-42e1-a1b4-0b245ba43d68
- 98a7fd3b-7404-4458-b4f1-6c1db41f4761
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
Expand Down Expand Up @@ -162,12 +162,12 @@ interactions:
Content-Type:
- application/json
User-Agent:
- ms-fabric-cli/1.5.0 (None; Linux/6.6.87.2-microsoft-standard-WSL2; Python/3.12.11)
- ms-fabric-cli/1.6.1 (None; Linux/6.12.76-linuxkit; Python/3.12.11)
method: POST
uri: https://api.fabric.microsoft.com/v1/workspaces
response:
body:
string: '{"id": "ace730cf-7c25-4530-9b0a-403d51a84a39", "displayName": "fabriccli_WorkspacePerTestclass_000001",
string: '{"id": "b1987dcd-b45c-4ba9-a9b6-bf7886f473a1", "displayName": "fabriccli_WorkspacePerTestclass_000001",
"description": "", "type": "Workspace", "capacityId": "00000000-0000-0000-0000-000000000004"}'
headers:
Access-Control-Expose-Headers:
Expand All @@ -177,17 +177,17 @@ interactions:
Content-Encoding:
- gzip
Content-Length:
- '176'
- '177'
Content-Type:
- application/json; charset=utf-8
Date:
- Thu, 23 Apr 2026 12:40:28 GMT
- Wed, 20 May 2026 08:33:59 GMT
Location:
- https://api.fabric.microsoft.com/v1/workspaces/ace730cf-7c25-4530-9b0a-403d51a84a39
- https://api.fabric.microsoft.com/v1/workspaces/b1987dcd-b45c-4ba9-a9b6-bf7886f473a1
Pragma:
- no-cache
RequestId:
- eb7cbfb1-6149-42ee-be23-1d20410cf305
- 04c05eb2-a6e9-4baf-95db-72e615086e80
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
Expand All @@ -213,13 +213,13 @@ interactions:
Content-Type:
- application/json
User-Agent:
- ms-fabric-cli/1.5.0 (cp; Linux/6.6.87.2-microsoft-standard-WSL2; Python/3.12.11)
- ms-fabric-cli/1.6.1 (cp; Linux/6.12.76-linuxkit; Python/3.12.11)
method: GET
uri: https://api.fabric.microsoft.com/v1/workspaces
response:
body:
string: '{"value": [{"id": "3634a139-2c9e-4205-910b-3b089a31be47", "displayName":
"My workspace", "description": "", "type": "Personal"}, {"id": "ace730cf-7c25-4530-9b0a-403d51a84a39",
"My workspace", "description": "", "type": "Personal"}, {"id": "b1987dcd-b45c-4ba9-a9b6-bf7886f473a1",
"displayName": "fabriccli_WorkspacePerTestclass_000001", "description": "",
"type": "Workspace", "capacityId": "00000000-0000-0000-0000-000000000004"}]}'
headers:
Expand All @@ -230,15 +230,15 @@ interactions:
Content-Encoding:
- gzip
Content-Length:
- '2341'
- '2621'
Content-Type:
- application/json; charset=utf-8
Date:
- Thu, 23 Apr 2026 12:42:41 GMT
- Wed, 20 May 2026 09:36:40 GMT
Pragma:
- no-cache
RequestId:
- 25e6e08e-5af6-458c-ad9e-53d5a72071c8
- 89b0c118-0064-4756-b37a-d3fc5cd41e9b
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
Expand All @@ -264,9 +264,9 @@ interactions:
Content-Type:
- application/json
User-Agent:
- ms-fabric-cli/1.5.0 (cp; Linux/6.6.87.2-microsoft-standard-WSL2; Python/3.12.11)
- ms-fabric-cli/1.6.1 (cp; Linux/6.12.76-linuxkit; Python/3.12.11)
method: GET
uri: https://api.fabric.microsoft.com/v1/workspaces/ace730cf-7c25-4530-9b0a-403d51a84a39/items
uri: https://api.fabric.microsoft.com/v1/workspaces/b1987dcd-b45c-4ba9-a9b6-bf7886f473a1/items
response:
body:
string: '{"value": []}'
Expand All @@ -282,11 +282,11 @@ interactions:
Content-Type:
- application/json; charset=utf-8
Date:
- Thu, 23 Apr 2026 12:42:42 GMT
- Wed, 20 May 2026 09:36:41 GMT
Pragma:
- no-cache
RequestId:
- cd3961eb-0065-455d-8c5f-9e0cf61c6cec
- 212a0afb-a5fc-4264-aa11-5fd48b1bdb13
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
Expand Down Expand Up @@ -314,9 +314,9 @@ interactions:
Content-Type:
- application/json
User-Agent:
- ms-fabric-cli/1.5.0 (cp; Linux/6.6.87.2-microsoft-standard-WSL2; Python/3.12.11)
- ms-fabric-cli/1.6.1 (cp; Linux/6.12.76-linuxkit; Python/3.12.11)
method: DELETE
uri: https://api.fabric.microsoft.com/v1/workspaces/ace730cf-7c25-4530-9b0a-403d51a84a39
uri: https://api.fabric.microsoft.com/v1/workspaces/b1987dcd-b45c-4ba9-a9b6-bf7886f473a1
response:
body:
string: ''
Expand All @@ -332,11 +332,11 @@ interactions:
Content-Type:
- application/octet-stream
Date:
- Thu, 23 Apr 2026 12:42:41 GMT
- Wed, 20 May 2026 09:36:41 GMT
Pragma:
- no-cache
RequestId:
- 727c197e-55e7-46a6-80f1-a427d424afc2
- 14de4349-b897-47d6-aaaf-9ed19260fe1e
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
Expand Down
Loading
Loading