Skip to content

Commit f3ab80f

Browse files
bejoyfuuulclaude
authored andcommitted
fix: use extension-aware fallback for output file resolution
- Use is_file() instead of exists() for stricter check - Match output files by expected extension before selecting - Raise explicit error when no matching output file found Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a10326b commit f3ab80f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • python/opendataloader-pdf-mcp/src/opendataloader_pdf_mcp

python/opendataloader-pdf-mcp/src/opendataloader_pdf_mcp/server.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ def convert_pdf(
155155
stem = input_file.stem
156156
output_file = Path(tmp_dir) / f"{stem}{ext}"
157157

158-
if not output_file.exists():
159-
# Fallback: find the first output file in the tmp dir
158+
if not output_file.is_file():
160159
files = [f for f in Path(tmp_dir).iterdir() if f.is_file()]
161160
if not files:
162161
raise RuntimeError(
163162
"Conversion completed but no output file was generated."
164163
)
165-
output_file = files[0]
164+
matching_ext = sorted(f for f in files if f.suffix == ext)
165+
if not matching_ext:
166+
raise RuntimeError(
167+
f"Conversion completed but no '{ext}' output file was generated."
168+
)
169+
output_file = matching_ext[0]
166170

167171
return output_file.read_text(encoding="utf-8")
168172

0 commit comments

Comments
 (0)