🐛 Raise a YAMLRocksError, not a bare ValueError, on malformed input encoding#175
Conversation
…ncoding A malformed byte encoding (a lone UTF-8 surrogate, odd-length or unpaired UTF-16, a non-scalar UTF-32 code point) was rejected with a raw PyO3 `ValueError` from `bytes_to_string`, outside the library's exception hierarchy. A caller doing `except yamlrocks.YAMLRocksError` would not catch it, and it carried none of the library's location attributes. Route the four decode-failure sites through `errors::decode_message`, which raises a `YAMLRocksDecodeError`. That stays inside the `YAMLRocksError` hierarchy while remaining a `ValueError` subclass, so existing `except ValueError` callers keep working too.
|
Warning Review limit reached
Next review available in: 8 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #175 +/- ##
==========================================
+ Coverage 92.37% 92.55% +0.18%
==========================================
Files 40 40
Lines 11201 11432 +231
==========================================
+ Hits 10347 10581 +234
+ Misses 854 851 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an exception-hierarchy leak: malformed byte-encoding input (lone UTF-8 surrogates, odd-length/unpaired UTF-16, out-of-range UTF-32) previously raised a bare PyO3 ValueError from bytes_to_string, which fell outside the library's YAMLRocksError hierarchy. It routes those failures through errors::decode_message, raising YAMLRocksDecodeError (a subclass of both YAMLRocksError and ValueError), so except YAMLRocksError now catches them while existing except ValueError callers are unaffected. This aligns the read path with the rest of the library's error model and improves the file-origin tagging and PyYAML-compat shim behavior for these cases.
Changes:
- Replaced bare
PyValueError::new_err(...)witherrors::decode_message(...)at the five encoding decode-failure sites. - Updated the
bytes_to_stringrustdoc to describe the newYAMLRocksDecodeErrorbehavior. - Added a parametrized regression test asserting malformed encodings raise
YAMLRocksErrorwhile stayingValueError-compatible.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/ffi/mod.rs |
Routes UTF-8/16/32 decode failures through errors::decode_message (→ YAMLRocksDecodeError) and updates the bytes_to_string docstring. |
tests/core/test_exceptions.py |
Adds a parametrized test verifying malformed encodings raise YAMLRocksError and remain ValueError-compatible. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Breaking change
None.
YAMLRocksDecodeErroris a subclass of bothYAMLRocksErrorandValueError, so any existingexcept ValueErrorkeeps catching these malformed-encoding failures; they now also fall underexcept YAMLRocksError.Proposed change
A malformed byte encoding (a lone UTF-8 surrogate, odd-length or unpaired UTF-16, a non-scalar UTF-32 code point) was rejected with a raw PyO3
ValueErrorfrombytes_to_string, outside the library's exception hierarchy. A caller catchingyamlrocks.YAMLRocksErrorwould miss it, and the error carried none of the library's attributes.This routes the four decode-failure sites through
errors::decode_message, raising aYAMLRocksDecodeError, which is inside theYAMLRocksErrorhierarchy and still aValueErrorsubclass. Added a parametrized regression test over the malformed-encoding cases across the read entry points.Type of change
Additional information
Checklist
uv run pytestpasses locally. A pull request cannot be merged unless CI is green.uv run ruff check .anduv run ruff format --check .pass.cargo fmt --checkandcargo clippy --all-targets -- -D warningspass.