GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Unify nul errors by joshuamegnauth54 · Pull Request #8339 · RustPython/RustPython

Conversation

@joshuamegnauth54

@joshuamegnauth54 joshuamegnauth54 commented Jul 20, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

  • Closes #xxxx
  • This PR follows our AI policy

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Standardized Python exceptions for embedded NUL characters and NUL bytes across path handling, codecs, text I/O, environment/process APIs, multiprocessing semaphores, OS/system calls, and network/SSL hostname/cipher handling.
    • Introduced dedicated NUL-focused exception helpers (including NUL byte variants) and updated mappings to raise the correct error type (TypeError vs ValueError) for NUL-containing inputs.
    • Improved error propagation in time and sound operations by preserving underlying failure details instead of generic embedded-NUL messages.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: c78cfb84-650e-4669-a963-44ea79616fb2

📥 Commits

Reviewing files that changed from the base of the PR and between d127606 and 4aa281a.

📒 Files selected for processing (16)
  • crates/stdlib/src/grp.rs
  • crates/stdlib/src/multiprocessing.rs
  • crates/stdlib/src/openssl.rs
  • crates/stdlib/src/ssl.rs
  • crates/vm/src/buffer.rs
  • crates/vm/src/exceptions.rs
  • crates/vm/src/function/fspath.rs
  • crates/vm/src/stdlib/_codecs.rs
  • crates/vm/src/stdlib/_io.rs
  • crates/vm/src/stdlib/_winapi.rs
  • crates/vm/src/stdlib/nt.rs
  • crates/vm/src/stdlib/os.rs
  • crates/vm/src/stdlib/pwd.rs
  • crates/vm/src/stdlib/time.rs
  • crates/vm/src/stdlib/winsound.rs
  • crates/vm/src/utils.rs
🚧 Files skipped from review as they are similar to previous changes (15)
  • crates/stdlib/src/grp.rs
  • crates/vm/src/stdlib/_io.rs
  • crates/vm/src/stdlib/_winapi.rs
  • crates/vm/src/stdlib/pwd.rs
  • crates/vm/src/stdlib/nt.rs
  • crates/vm/src/utils.rs
  • crates/stdlib/src/openssl.rs
  • crates/stdlib/src/ssl.rs
  • crates/vm/src/stdlib/time.rs
  • crates/vm/src/buffer.rs
  • crates/vm/src/stdlib/winsound.rs
  • crates/stdlib/src/multiprocessing.rs
  • crates/vm/src/stdlib/os.rs
  • crates/vm/src/exceptions.rs
  • crates/vm/src/stdlib/_codecs.rs

📝 Walkthrough

Walkthrough

The 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.

Changes

Embedded-NUL exception standardization

Layer / File(s) Summary
Centralized NUL error contract
crates/vm/src/exceptions.rs, crates/vm/src/buffer.rs
Adds NulError, character/byte error helpers, updated ToPyException mappings, and standardized buffer-format parsing errors.
VM NUL validation paths
crates/vm/src/function/fspath.rs, crates/vm/src/stdlib/*, crates/vm/src/utils.rs
Routes NUL validation and Rust conversion failures through standardized character or byte exceptions.
Standard-library NUL validation paths
crates/stdlib/src/grp.rs, crates/stdlib/src/multiprocessing.rs, crates/stdlib/src/openssl.rs, crates/stdlib/src/ssl.rs
Updates group, semaphore, OpenSSL, and SSL hostname handling to use standardized NUL exceptions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • RustPython/RustPython#8245: Both changes update shared embedded-NUL error conversion plumbing in crates/vm/src/exceptions.rs.

Suggested reviewers: shaharnaveh

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: standardizing embedded NUL error handling across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ShaharNaveh
ShaharNaveh approved these changes Jul 20, 2026
View reviewed changes

@ShaharNaveh ShaharNaveh left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't realized it duplicated like that. tysm!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

joshuamegnauth54 reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@joshuamegnauth54
joshuamegnauth54 marked this pull request as draft July 20, 2026 19:34
coderabbitai[bot]
coderabbitai Bot reviewed Jul 20, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
crates/vm/src/stdlib/time.rs (1)

571-578: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use a helper closure to deduplicate the ASCII buffer flush logic.

The logic for flushing ascii to out is 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

📥 Commits

Reviewing files that changed from the base of the PR and between cc30cd5 and 31b6e13.

📒 Files selected for processing (15)
  • crates/stdlib/src/grp.rs
  • crates/stdlib/src/multiprocessing.rs
  • crates/stdlib/src/openssl.rs
  • crates/stdlib/src/ssl.rs
  • crates/vm/src/buffer.rs
  • crates/vm/src/exceptions.rs
  • crates/vm/src/function/fspath.rs
  • crates/vm/src/stdlib/_codecs.rs
  • crates/vm/src/stdlib/_io.rs
  • crates/vm/src/stdlib/nt.rs
  • crates/vm/src/stdlib/os.rs
  • crates/vm/src/stdlib/pwd.rs
  • crates/vm/src/stdlib/time.rs
  • crates/vm/src/stdlib/winsound.rs
  • crates/vm/src/utils.rs

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/vm/src/stdlib/nt.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread crates/vm/src/stdlib/winsound.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@joshuamegnauth54
joshuamegnauth54 marked this pull request as ready for review July 21, 2026 01:19
@joshuamegnauth54
joshuamegnauth54 force-pushed the unify-nul-errors branch from 31b6e13 to 9598e8c Compare July 21, 2026 01:19
@joshuamegnauth54

joshuamegnauth54 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Additionally, MissingNulTerminator now raises an exception with the correct message. The original message was "embedded null character," but the error is for byte slices that lack any NULs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joshuamegnauth54
joshuamegnauth54 force-pushed the unify-nul-errors branch 2 times, most recently from 07d6c70 to d127606 Compare July 21, 2026 02:21
@joshuamegnauth54

joshuamegnauth54 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

See #8343 for info on the Ubuntu failure.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joshuamegnauth54
Unify nul errors
4aa281a
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`.
@joshuamegnauth54
joshuamegnauth54 force-pushed the unify-nul-errors branch from d127606 to 4aa281a Compare July 22, 2026 23:26
youknowone
youknowone approved these changes Jul 23, 2026
View reviewed changes

@youknowone youknowone left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, looking a lot better. thank you!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@youknowone
youknowone merged commit c6b80e8 into RustPython:main Jul 23, 2026
26 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@joshuamegnauth54
joshuamegnauth54 deleted the unify-nul-errors branch July 24, 2026 01:55
@coderabbitai coderabbitai Bot mentioned this pull request Jul 25, 2026
Use memchr consistently for NUL checks #8372
Merged
1 of 2 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 2026
ffi: No interior NULs (part 1) #8245
Merged
1 of 2 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 19, 2026
host_env: Reject interior NULs for CreateProcessW #8555
Merged
1 of 2 tasks
youknowone pushed a commit that referenced this pull request Sep 16, 2026
@joshuamegnauth54
Unify nul errors (#8339)
05564d9
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
@youknowone youknowone youknowone approved these changes
@ShaharNaveh ShaharNaveh ShaharNaveh approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@joshuamegnauth54 @youknowone @ShaharNaveh
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.