fix: raise HTTP errors in ApiClient instead of returning None (#820)#1128
Open
agodianel wants to merge 1 commit intomlco2:masterfrom
Open
fix: raise HTTP errors in ApiClient instead of returning None (#820)#1128agodianel wants to merge 1 commit intomlco2:masterfrom
agodianel wants to merge 1 commit intomlco2:masterfrom
Conversation
) Resolves mlco2#820 by raising requests.exceptions.HTTPError when the API returns a non-success status code, rather than failing silently and returning None. This allows the EmissionsTracker to catch the exception and fall back to offline mode without crashing the user's execution run.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1128 +/- ##
==========================================
+ Coverage 80.74% 80.87% +0.13%
==========================================
Files 41 41
Lines 3921 3927 +6
==========================================
+ Hits 3166 3176 +10
+ Misses 755 751 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #820 by raising requests.exceptions.HTTPError when the API returns a non-success status code, rather than failing silently and returning None. This allows the EmissionsTracker to catch the exception and fall back to offline mode without crashing the user's execution run.
Description
Fixes #820
The ApiClient previously returned
NoneorFalseon HTTP errors, which failed silently for the user but occasionally crashed upstream logic (e.g. attempting to readapi.run_idwhen it wasNone). As requested in the issue, this PR updates the client to throwrequests.exceptions.HTTPErroron bad status codes and handles the exception upstream to fall back gracefully.Changes:
return None/False/[]withr.raise_for_status()in all ApiClient data methods.try...exceptblocks within ApiClient (e.g., inside _create_run).try...exceptblock so that if the API is unreachable, the execution falls back to local tracking instead of tearing down the user's workload.All local CodeCarbon unit tests (including the new ones) execute and pass successfully.