Skip to content

Commit 5e85793

Browse files
committed
fix: 🐛 File Not Found Error when submitting a form whose pdf is not found
1 parent 3fc0cb6 commit 5e85793

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/file_manipulator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def fill_form(self, user_input: str, fields: list, pdf_form_path: str, model: st
4343
print(f"[2] PDF template path: {pdf_form_path}")
4444

4545
if not os.path.exists(pdf_form_path):
46-
print(f"Error: PDF template not found at {pdf_form_path}")
47-
return None # Or raise an exception
46+
raise FileNotFoundError(f"PDF template not found at {pdf_form_path}")
4847

4948
print("[3] Starting extraction and PDF filling process...")
5049
try:

tests/test_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ def test_fill_form_missing_template(self, client, mock_controller):
202202
})
203203
assert resp.status_code == 404
204204

205+
def test_fill_form_template_file_not_found(self, client, mock_controller):
206+
tpl_id = self._seed_template(client, mock_controller)
207+
mock_controller["form_ctrl"].fill_form.side_effect = FileNotFoundError("PDF template not found")
208+
209+
resp = client.post("/forms/fill", json={
210+
"template_id": tpl_id,
211+
"input_text": "some text",
212+
})
213+
assert resp.status_code == 500
214+
assert "PDF template not found" in resp.json()["error"]
215+
205216
def test_fill_form_validates_body(self, client):
206217
"""Missing required fields → 422."""
207218
resp = client.post("/forms/fill", json={})

0 commit comments

Comments
 (0)