Skip to content

fix: handle Windows UTF-8 output and MinerU JSON errors - #3

Merged
blessonism merged 2 commits into
mainfrom
fix/issue-2-windows-utf8-mineru-errors
Mar 17, 2026
Merged

fix: handle Windows UTF-8 output and MinerU JSON errors#3
blessonism merged 2 commits into
mainfrom
fix/issue-2-windows-utf8-mineru-errors

Conversation

@blessonism

@blessonism blessonism commented Mar 17, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #2 by addressing two issues reported in Windows environments:

  1. Windows UTF-8 output crash: search.py now configures stdout/stderr to UTF-8 at startup (best-effort, silent fallback).
  2. MinerU error misclassification: content_extract.py now parses stdout as JSON first; only marks as "wrapper crashed" when both exit code is non-zero AND stdout is not valid JSON.

Changes

  • search-layer/scripts/search.py: Added _configure_stdio_utf8() helper, called at module load.
  • content-extract/scripts/content_extract.py: Refactored subprocess result handling to distinguish structured JSON errors from true crashes; added _error_output() helper for consistent error payloads.

Validation

  • UTF-8 stdio: Verified reconfigure(encoding='utf-8') is called on streams that support it.
  • MinerU error handling: Confirmed that exit code 2 + valid JSON error payload is correctly classified as structured error (not "wrapper crashed").
  • True crash scenario: Confirmed that non-JSON output + non-zero exit is still classified as "wrapper crashed".

Notes

  • When items is empty, the script now preserves the downstream non-zero return code (e.g. 2) instead of always returning 1, allowing structured error payloads to propagate their original exit code.
  • No breaking changes to existing success/error contract.

Closes #2.

Summary by CodeRabbit

  • Bug Fixes

    • Standardized error message formatting across failure scenarios for more consistent and reliable error reporting.
    • Enhanced error collection and reporting when processing encounters issues, providing clearer failure details.
  • Chores

    • Improved UTF-8 character encoding support for better handling of international text and special characters.

@coderabbitai

coderabbitai Bot commented Mar 17, 2026

Copy link
Copy Markdown

Note

Docstrings generation - SKIPPED
Skipped regeneration as there are no new commits. Docstrings already generated for this pull request at #4.

@coderabbitai

coderabbitai Bot commented Mar 17, 2026

Copy link
Copy Markdown

Caution

Docstrings generation - FAILED

An unexpected error occurred while opening a pull request: Update is not a fast forward - https://docs.github.com/rest/git/refs#update-a-reference

@coderabbitai

coderabbitai Bot commented Mar 17, 2026

Copy link
Copy Markdown

No open human review comments were found in this PR to create a plan for.

coderabbitai Bot added a commit that referenced this pull request Mar 17, 2026
Docstrings generation was requested by @coderabbitai[bot].

* #3 (comment)

The following files were modified:

* `content-extract/scripts/content_extract.py`
* `search-layer/scripts/search.py`
Repository owner deleted a comment from coderabbitai Bot Mar 17, 2026
Repository owner deleted a comment from coderabbitai Bot Mar 17, 2026
Repository owner deleted a comment from coderabbitai Bot Mar 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@content-extract/scripts/content_extract.py`:
- Around line 99-103: The parsed JSON assigned to variable j from
json.loads(p.stdout) may be a non-dict (e.g., list or primitive) so calls to
j.get(...) will raise; update the post-parse logic around json.loads(p.stdout)
and the later usage at the j.get(...) call to guard the type: after
json.loads(p.stdout) validate isinstance(j, dict) (or coerce to an empty dict)
and only call j.get(...) when j is a dict, otherwise handle the non-dict case
(e.g., treat as parse error or extract expected value differently) so the
structured error contract is preserved; references: variable j,
json.loads(p.stdout), and the j.get(...) usage.
- Around line 105-106: The crash-detection logic incorrectly treats exit code 1
as non-crash; update the condition around p.returncode in content_extract.py
(the block that assigns out = _error_output) so it treats any non-zero exit code
as a crash—e.g., replace the current "if p.returncode not in (0, 1):" check with
a strict non-zero check (p.returncode != 0) so exit code 1 is classified as a
crash and routed through _error_output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7ebb8509-1955-4a3c-ba5c-806a2bf6543f

📥 Commits

Reviewing files that changed from the base of the PR and between 99f7b31 and 97c6bf9.

📒 Files selected for processing (2)
  • content-extract/scripts/content_extract.py
  • search-layer/scripts/search.py

Comment thread content-extract/scripts/content_extract.py
Comment thread content-extract/scripts/content_extract.py Outdated
Repository owner deleted a comment from coderabbitai Bot Mar 17, 2026
@coderabbitai

coderabbitai Bot commented Mar 17, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6248ead6-3ad4-40c1-befc-40da80fee6e1

📥 Commits

Reviewing files that changed from the base of the PR and between 97c6bf9 and 95d215f.

📒 Files selected for processing (1)
  • content-extract/scripts/content_extract.py

📝 Walkthrough

Walkthrough

Two scripts receive targeted fixes: search.py gains UTF-8 stdio configuration to prevent Windows console encoding crashes, while content_extract.py centralizes error output formatting and refines error detection to distinguish between actual MinerU wrapper crashes and structured JSON errors.

Changes

Cohort / File(s) Summary
Error Handling Standardization
content-extract/scripts/content_extract.py
Added _error_output() helper to standardize error JSON structure. Refactored all error paths to use this function instead of inline dictionaries. Enhanced logic to parse JSON output first before labeling as crash; collects error messages from parsed JSON when items are absent; adjusted return semantics for "no items" case.
UTF-8 Stdio Configuration
search-layer/scripts/search.py
Added _configure_stdio_utf8() helper that reconfigures stdout/stderr to UTF-8 on platforms with legacy console encodings. Function is invoked at startup (before requests import) to prevent UnicodeEncodeError on Windows terminals with GBK/cp936 encodings. Wrapped in broad try/except for broad platform compatibility.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A hop through error paths so grand,
UTF-8 flows across the land,
No more crashes on Windows shell,
Structured errors parse so well!
Error output sings in standardized song. 🎵

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-2-windows-utf8-mineru-errors
📝 Coding Plan
  • Generate coding plan for human review comments

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

Tip

CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.

Add a .trivyignore file to your project to customize which findings Trivy reports.

@blessonism
blessonism merged commit f0eb76d into main Mar 17, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows UTF-8 output crash in search.py + content_extract misclassifies MinerU JSON errors

1 participant