Unify nul errors#8339
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (16)
🚧 Files skipped from review as they are similar to previous changes (13)
📝 WalkthroughWalkthroughThe change introduces shared embedded-NUL error types and helpers, updates Rust error conversions, and replaces hard-coded or generic NUL-related exceptions across VM and standard-library paths. ChangesEmbedded-NUL exception standardization
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
ShaharNaveh
left a comment
There was a problem hiding this comment.
I haven't realized it duplicated like that. tysm!
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
crates/vm/src/stdlib/time.rs (1)
571-578: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse a helper closure to deduplicate the ASCII buffer flush logic.
The logic for flushing
asciitooutis duplicated three times. Consider extracting it into a closure to improve maintainability.♻️ Proposed refactor
let mut out = Wtf8Buf::new(); let mut ascii = String::new(); + let mut flush_ascii = |ascii: &mut String, out: &mut Wtf8Buf| -> PyResult<()> { + if !ascii.is_empty() { + let part = + host_time::strftime_ascii(ascii, &tm).map_err(|e| e.to_pyexception(vm))?; + out.extend(part.chars()); + ascii.clear(); + } + Ok(()) + }; + for codepoint in format.as_wtf8().code_points() { if codepoint.to_u32() == 0 { - if !ascii.is_empty() { - let part = - host_time::strftime_ascii(&ascii, &tm).map_err(|e| e.to_pyexception(vm))?; - out.extend(part.chars()); - ascii.clear(); - } + flush_ascii(&mut ascii, &mut out)?; out.push(codepoint); continue; } if let Some(ch) = codepoint.to_char() && ch.is_ascii() { ascii.push(ch); continue; } - if !ascii.is_empty() { - let part = - host_time::strftime_ascii(&ascii, &tm).map_err(|e| e.to_pyexception(vm))?; - out.extend(part.chars()); - ascii.clear(); - } + flush_ascii(&mut ascii, &mut out)?; out.push(codepoint); } - if !ascii.is_empty() { - let part = host_time::strftime_ascii(&ascii, &tm).map_err(|e| e.to_pyexception(vm))?; - out.extend(part.chars()); - } + flush_ascii(&mut ascii, &mut out)?; Ok(out.to_pyobject(vm))Also applies to: 589-598
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/vm/src/stdlib/time.rs` around lines 571 - 578, In the time-formatting loop, extract the repeated non-empty `ascii` buffer flush into a local helper closure that calls `host_time::strftime_ascii`, extends `out`, and clears `ascii`; replace all three duplicated flush blocks with this closure while preserving error propagation and existing output behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/vm/src/stdlib/nt.rs`:
- Line 555: Update the error return in the null-character handling path to call
nul_char_error through its fully qualified exceptions module path and pass the
in-scope vm argument.
In `@crates/vm/src/stdlib/winsound.rs`:
- Line 145: Update the error return in the winsound function to reference the
exceptions module through its fully qualified path, preserving the existing
nul_char_error(vm) behavior without adding an import.
---
Nitpick comments:
In `@crates/vm/src/stdlib/time.rs`:
- Around line 571-578: In the time-formatting loop, extract the repeated
non-empty `ascii` buffer flush into a local helper closure that calls
`host_time::strftime_ascii`, extends `out`, and clears `ascii`; replace all
three duplicated flush blocks with this closure while preserving error
propagation and existing output behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 9bbc6a49-f35c-4f0b-b376-cd49a5c8e422
📒 Files selected for processing (15)
crates/stdlib/src/grp.rscrates/stdlib/src/multiprocessing.rscrates/stdlib/src/openssl.rscrates/stdlib/src/ssl.rscrates/vm/src/buffer.rscrates/vm/src/exceptions.rscrates/vm/src/function/fspath.rscrates/vm/src/stdlib/_codecs.rscrates/vm/src/stdlib/_io.rscrates/vm/src/stdlib/nt.rscrates/vm/src/stdlib/os.rscrates/vm/src/stdlib/pwd.rscrates/vm/src/stdlib/time.rscrates/vm/src/stdlib/winsound.rscrates/vm/src/utils.rs
31b6e13 to
9598e8c
Compare
|
Additionally, |
9598e8c to
07d6c70
Compare
Part of RustPython#8245 to reduce the amount of work needed to review. I simplified the embedded nul errors by forwarding to the implementations in `vm::exceptions`.
07d6c70 to
d127606
Compare
|
See #8343 for info on the Ubuntu failure. |
Part of #8245 to reduce the amount of work needed to review. I simplified the embedded nul errors by forwarding to the implementations in
vm::exceptions.Summary
Summary by CodeRabbit