bytedance / bytedance/pdf-parser

fix: preserve output error contract during initialization

Open
#13 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14
Forks
9
Avg merge
43m
Merged PRs (30d)
1

Description

## Problem

`parse_file()` initializes the output directory before entering its existing exception-handling block. If directory setup raises an `OutputWriteError`, the exception bypasses the documented CLI error envelope and exit code 40 path.

This affects current `main` at `c6478aae9ab50a13fc54c0599a0a459396c15b99` and release `0.0.5`.

## Minimal reproduction

```python
from pathlib import Path
from unittest.mock import patch

from hi_pdf_parser.errors import OutputWriteError
from hi_pdf_parser.runner import parse_file

with patch(
"hi_pdf_parser.runner.ow.prepare_output_dir",
side_effect=OutputWriteError("output denied"),
):
parse_file(Path("tests/fixtures/normal.pdf"), Path("out"), None)
```

## Actual behavior

`OutputWriteError` escapes `parse_file()`. `main()` does not catch `CliError`, so the exception reaches the caller; the CLI emits no error envelope or mapped return code.

## Expected behavior

`parse_file()` should return an error envelope with `error_type` `OUTPUT_WRITE_FAILURE` and exit code 40, matching `hi_pdf_parser.errors` and the handling already used for later write failures.

## Impact

Common output initialization failures such as permission errors or invalid destinations can produce no machine-readable error or mapped exit status, making automation unable to handle the documented output-failure contract.

## Suggested implementation

Include output-directory and file-handler initialization in the existing exception boundary, and make cleanup conditional when the handler was not attached. Add a regression test for initialization failure.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in hi_pdf_parser/runner.py by reading parse_file(), its existing exception boundary, and the later write-failure handling; then check the error definitions in hi_pdf_parser/errors.py. Add the regression test described by the reproduction for initialization failure. Done means the failure returns an OUTPUT_WRITE_FAILURE envelope and mapped exit code 40, with cleanup safe when no handler was attached.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.