From deeafed7a94a1e91609a11976ef16ee03a1f5fac Mon Sep 17 00:00:00 2001 From: jedarden Date: Sun, 31 May 2026 14:12:33 -0400 Subject: [PATCH] fix(test): add error handling for missing fixture paths - Add .ok_or_else() error handling after resolve_fixture_path() - Prevents panics when fixtures are not found - Applies to: extract_text, extract_markdown, extract_stream, search, get_metadata, hash, classify --- .needle-predispatch-sha | 2 +- crates/pdftract-core/tests/conformance.rs | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.needle-predispatch-sha b/.needle-predispatch-sha index 6a4d042..50d9fea 100644 --- a/.needle-predispatch-sha +++ b/.needle-predispatch-sha @@ -1 +1 @@ -d22d9a49026773048d23e0f0f9c580f657b1ade0 +9cf1ccffa9b1213b83079e66d9a245aadc6d584f diff --git a/crates/pdftract-core/tests/conformance.rs b/crates/pdftract-core/tests/conformance.rs index de93342..c946982 100644 --- a/crates/pdftract-core/tests/conformance.rs +++ b/crates/pdftract-core/tests/conformance.rs @@ -408,7 +408,8 @@ fn run_extract_test(case: &TestCase) -> Result<(Value, Vec)> { /// Run the "extract_text" method test case. fn run_extract_text_test(case: &TestCase) -> Result<(Value, Vec)> { - let fixture_path = resolve_fixture_path(&case.fixture); + let fixture_path = resolve_fixture_path(&case.fixture) + .ok_or_else(|| anyhow!("Fixture path not found: {}", case.fixture))?; let options = options_from_value(&case.options); let text = extract_text(&fixture_path, &options) @@ -444,7 +445,8 @@ fn run_extract_text_test(case: &TestCase) -> Result<(Value, Vec)> { /// Run the "extract_markdown" method test case. fn run_extract_markdown_test(case: &TestCase) -> Result<(Value, Vec)> { - let fixture_path = resolve_fixture_path(&case.fixture); + let fixture_path = resolve_fixture_path(&case.fixture) + .ok_or_else(|| anyhow!("Fixture path not found: {}", case.fixture))?; let options = options_from_value(&case.options); let extract_result = extract_pdf(&fixture_path, &options) @@ -493,7 +495,8 @@ fn run_extract_markdown_test(case: &TestCase) -> Result<(Value, Vec)> { /// Run the "extract_stream" method test case. fn run_extract_stream_test(case: &TestCase) -> Result<(Value, Vec)> { - let fixture_path = resolve_fixture_path(&case.fixture); + let fixture_path = resolve_fixture_path(&case.fixture) + .ok_or_else(|| anyhow!("Fixture path not found: {}", case.fixture))?; let options = options_from_value(&case.options); let mut buffer = Vec::new(); @@ -539,7 +542,8 @@ fn run_extract_stream_test(case: &TestCase) -> Result<(Value, Vec)> { /// Run the "search" method test case. fn run_search_test(case: &TestCase) -> Result<(Value, Vec)> { - let fixture_path = resolve_fixture_path(&case.fixture); + let fixture_path = resolve_fixture_path(&case.fixture) + .ok_or_else(|| anyhow!("Fixture path not found: {}", case.fixture))?; let options = options_from_value(&case.options); // Extract text first, then search @@ -629,7 +633,8 @@ fn run_search_test(case: &TestCase) -> Result<(Value, Vec)> { /// Run the "get_metadata" method test case. fn run_get_metadata_test(case: &TestCase) -> Result<(Value, Vec)> { - let fixture_path = resolve_fixture_path(&case.fixture); + let fixture_path = resolve_fixture_path(&case.fixture) + .ok_or_else(|| anyhow!("Fixture path not found: {}", case.fixture))?; // Use the SDK's get_metadata function for accurate metadata match pdftract_core::sdk::get_metadata(&fixture_path) { @@ -656,7 +661,8 @@ fn run_get_metadata_test(case: &TestCase) -> Result<(Value, Vec)> { /// Run the "hash" method test case. fn run_hash_test(case: &TestCase) -> Result<(Value, Vec)> { - let fixture_path = resolve_fixture_path(&case.fixture); + let fixture_path = resolve_fixture_path(&case.fixture) + .ok_or_else(|| anyhow!("Fixture path not found: {}", case.fixture))?; // Extract to get the fingerprint let options = options_from_value(&case.options); @@ -685,7 +691,8 @@ fn run_hash_test(case: &TestCase) -> Result<(Value, Vec)> { /// Run the "classify" method test case. fn run_classify_test(case: &TestCase) -> Result<(Value, Vec)> { - let fixture_path = resolve_fixture_path(&case.fixture); + let fixture_path = resolve_fixture_path(&case.fixture) + .ok_or_else(|| anyhow!("Fixture path not found: {}", case.fixture))?; let options = options_from_value(&case.options); let result = extract_pdf(&fixture_path, &options)