Skip to content

fix: improve default error handling #1379 #1409#1439

Draft
Alexj9837 wants to merge 3 commits intomainfrom
chore/improve-default-error-handling-1379-1409
Draft

fix: improve default error handling #1379 #1409#1439
Alexj9837 wants to merge 3 commits intomainfrom
chore/improve-default-error-handling-1379-1409

Conversation

@Alexj9837
Copy link

Fixes #1379
Fixes #1409

Both issues related to error handling in the REST client.

1379 - Catches 'UnauthorisedAccessErrorexplicitly instead of string-matching onBlueskyRemoteControlError`.

1409 - Expands the exception hierarchy so each
HTTP status code raises a distinct typed exception rather than bundling
everything into BlueskyRemoteControlError.

Tests

  • Update tests to match new exception signatures
  • Add missing coverage for 422 non-list detail response
  • Add missing coverage for streaming error in run command

@Alexj9837 Alexj9837 self-assigned this Mar 10, 2026
@Alexj9837 Alexj9837 force-pushed the chore/improve-default-error-handling-1379-1409 branch from accdd8c to c5ab6b3 Compare March 10, 2026 14:20
@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.26%. Comparing base (485e0f8) to head (05150ae).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1439      +/-   ##
==========================================
+ Coverage   95.19%   95.26%   +0.07%     
==========================================
  Files          43       43              
  Lines        3119     3125       +6     
==========================================
+ Hits         2969     2977       +8     
+ Misses        150      148       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Alexj9837 Alexj9837 force-pushed the chore/improve-default-error-handling-1379-1409 branch from c5ab6b3 to 883b09e Compare March 11, 2026 09:39
@Alexj9837 Alexj9837 removed their assignment Mar 11, 2026
@Alexj9837 Alexj9837 force-pushed the chore/improve-default-error-handling-1379-1409 branch from 883b09e to 05150ae Compare March 11, 2026 11:06
Comment on lines +45 to 46
class BlueskyRemoteControlError(BlueskyRequestError):
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can stay as Exception
Because you are not using the code part of it in the 3 exception that are changed above.

Comment on lines +49 to +50
class NotFoundError(BlueskyRequestError):
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I coundnt understand what peter said in the issue but it
look like the issue was to change the name from KeyError to
NotFoundError which make sense in more case ?

Comment on lines +138 to +140
return BlueskyRequestError(code, str(response))
else:
return BlueskyRequestError(code, response.text)
return BlueskyRequestError(code, str(response))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can stay as response.text
and same for the above

Comment on lines 247 to +248
def test_get_non_existent_plan(rest_client: BlueapiRestClient):
with pytest.raises(KeyError, match="{'detail': 'Item not found'}"):
with pytest.raises(NotFoundError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the match string be added back ?
it is good to check the type of error but if we have match details we should check for them as well


def test_create_task_validation_error(rest_client: BlueapiRestClient):
with pytest.raises(BlueskyRequestError, match="Internal Server Error"):
with pytest.raises(BlueskyRequestError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment on lines 134 to +135
isinstance(result.exception, BlueskyRemoteControlError)
and result.exception.args == ("Response [450]",)
and result.exception.args[1] == "Response [450]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can stay same as before and if other new errors are added
We can check for them

Comment on lines 680 to +681
)
assert result.exception.args[0] == "Failed to tear down the environment"
assert result.exception.args[1] == "Failed to tear down the environment"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exception is in args[0] ?

Comment on lines +68 to +70
(401, None, UnauthorisedAccessError(401, "")),
(403, None, UnauthorisedAccessError(403, "")),
(404, None, UnknownPlanError(404, "")),
Copy link
Contributor

@ZohebShaikh ZohebShaikh Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Content can also be checked

Copy link
Contributor

@ZohebShaikh ZohebShaikh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good only few things can be tidied up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve default error handling Remove stacktrace from error message when not logged into CLI

2 participants