fix(exceptions): preserve falsy-but-valid values in dataset.py and cli.py - #279
Conversation
…i.py Extends the fix already applied to metric.py (59e5e65) to InvalidDatasetError (line_number=0) and ValidationError (field='', value=''), which had the same 'if x:' truthiness bug instead of 'if x is not None:'. Adds regression tests covering both the falsy-valid case and the genuinely-absent (None) case for all three exception types. Fixes OpenAgentHQ#68
There was a problem hiding this comment.
Pull request overview
This PR fixes a common truthiness pitfall in exception constructors so that falsy-but-valid values (e.g., 0 and "") are preserved in exception details and therefore remain visible in str(error) output/logging.
Changes:
- Update
InvalidDatasetErrorto includeline_number=0indetailsby usingis not None. - Update
ValidationErrorto include empty-stringfield/valueindetailsby usingis not None. - Add targeted regression tests covering
0vsNoneand""vsNonebehavior for these exceptions (and forMetricTimeoutErroras well).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/unit/test_exceptions.py | Adds regression tests ensuring falsy-but-valid values are preserved in exception details and string rendering. |
| openagent_eval/exceptions/dataset.py | Fixes line_number handling so 0 is retained (only None is omitted). |
| openagent_eval/exceptions/cli.py | Fixes field/value handling so empty strings are retained (only None is omitted). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/oc review pr |
PR Review: #279 — fix(exceptions): preserve falsy-but-valid valuesVerdict: Approve. Small, correct, well-tested fix. SummaryReplaces truthiness checks ( What I verified
Test qualityGood coverage — each fix gets a "preserve falsy" test and an "omit None" test, and the timeout tests also lock in the pre-existing fix's Notes (non-blocking)
Nothing blocking merge. |
|
🎉 Congratulations @PrinceThummar011! Your pull request has been successfully merged into main. 🚀 Thank you for contributing to OpenAgentHQ and helping improve the project. We truly appreciate your contribution and hope to see you back with more amazing PRs! Happy Open Sourcing! ❤️ |
…dropping them (#280) Detail-recording guards used truthiness tests, so an explicitly passed "", 0, False or [] was silently dropped from .details. Only None means "not supplied". Switch all 21 guards in the exceptions package to `is not None`, matching the fix that landed for #68 in PR #279. Message-text construction guards and __str__ formatting are unchanged. Co-Authored-By: Kimi K3 <noreply@kimi.com>

Fixes #68
Summary of Changes
openagent_eval/exceptions/metric.py(around line 119):mainin commit59e5e65(if timeout_seconds is not None:).openagent_eval/exceptions/dataset.py(line 84):if line_number:withif line_number is not None:. Preservesline_number=0.openagent_eval/exceptions/cli.py(lines 90-93):if field:andif value:withif field is not None:andif value is not None:. Preservesfield=""andvalue="".Contributor Claim Verification
metric.pyhad been updated in an earlier commit,dataset.pyandcli.pystill contained the exact same truthiness bug.Regression Tests Added
test_invalid_dataset_error_preserves_zero_line_number(line_number=0)test_invalid_dataset_error_omits_none_line_number(line_number=None)test_timeout_error_preserves_zero_timeout(timeout_seconds=0.0)test_timeout_error_omits_none_timeout(timeout_seconds=None)test_validation_error_preserves_empty_string_field_and_value(field="",value="")test_validation_error_omits_none_field_and_value(field=None,value=None)