fix: raise on offline tracker configuration errors - #1334
Open
davidberenstein1957 wants to merge 2 commits into
Open
fix: raise on offline tracker configuration errors#1334davidberenstein1957 wants to merge 2 commits into
davidberenstein1957 wants to merge 2 commits into
Conversation
`@suppress(Exception)` on `OfflineEmissionsTracker.__init__` swallowed configuration errors such as a missing `output_dir`, returning a half-built object with no `_start_time`, `_hardware` or `_scheduler`. `start()`/`stop()` then failed silently and no emissions were recorded. Construction now raises, matching `EmissionsTracker`. The suppression on `start`/`flush`/`stop` is kept, so runtime measurement errors still cannot crash a user's job. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1334 +/- ##
==========================================
+ Coverage 91.39% 91.47% +0.07%
==========================================
Files 49 49
Lines 5056 5055 -1
==========================================
+ Hits 4621 4624 +3
+ Misses 435 431 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
davidberenstein1957
marked this pull request as ready for review
August 12, 2026 19:14
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.
Closes #1311
What changed
Removed
@suppress(Exception)fromOfflineEmissionsTracker.__init__(codecarbon/emissions_tracker.py).Why
The decorator swallowed configuration errors raised during construction, most visibly the
OSErrorfrom_set_from_confwhenoutput_dirdoes not exist. The constructor then returned an object that had never reached_initialize_runtime_state()/_initialize_scheduler_state(), so it had no_start_time,_hardware,_scheduleror_output_handlers. The subsequentstart()andstop()calls are themselves suppressed, so they degraded intoAttributeErrorwarnings and the run finished with no emissions file and no exception. Under the CLI defaultlog_level="error"nothing was printed at all.The online
EmissionsTrackeralready raises for the same input, so this also removes an asymmetry between the two constructors.Suppression on
start,flushandstopis deliberately left in place: runtime measurement errors must never crash a user job. Only construction, where the object invariants were never established, now fails loudly.Verification
Added
test_offline_tracker_raises_on_invalid_output_dirintests/test_offline_emissions_tracker.py, asserting both the offline and the online tracker raiseOSErrorfor a non-existentoutput_dir. It fails on master and passes with this change.Note for reviewers
This is a behaviour change at a public boundary: code that today constructs a misconfigured offline tracker and carries on will now raise. That is the intended correction but it deserves a changelog entry, and ideally a minor release.
🤖 Generated with Claude Code
Changelog / release note (added)
CHANGELOG.mdis not onmasteryet (it lands withdocs/traction-batch), so the entry lives in the docs:docs/reference/api.mdnow carries a "Constructor errors (changed in v3.4.0)" warning. When the changelog lands, copy:This must ride a minor release (3.4.0), not a patch.
A second constructor-raise case is now covered:
test_offline_tracker_raises_on_invalid_regionexercises the offline-only region check, which runs beforesuper().__init__and so was suppressed by a different code path than theoutput_dirOSError. Both new tests fail when@suppress(Exception)is put back on the constructor.