Fixed a broken document being sent to the AI as a partially read file

This commit is contained in:
Thorsten Sommer 2026-08-10 20:28:36 +02:00
parent 96cc4c4976
commit 791d623d67
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -1055,13 +1055,20 @@ async fn stream_document(file_path: &str, extract_images: bool, stream_id: &str)
let mut number_of_pages = 0; let mut number_of_pages = 0;
let mut number_of_characters = 0; let mut number_of_characters = 0;
//
// A failing page ends the whole document here, unlike a PDF page: the page iterator gives
// up for good once it hit an error, so everything behind that page is lost as well. This
// is why neither failure below reports `PageExtractionFailed`. That code means that a
// single page is missing while the rest stays usable, and the app would hand the truncated
// document to the AI on those grounds.
//
for page_result in pages { for page_result in pages {
let page = match page_result { let page = match page_result {
Ok(page) => page, Ok(page) => page,
Err(e) => { Err(e) => {
error!("A page of the document '{path:?}' could not be read: {e}"); error!("A page of the document '{path:?}' could not be read: {e}");
let _ = tx.blocking_send(Err(ExtractionError::new( let _ = tx.blocking_send(Err(ExtractionError::new(
ExtractionErrorCode::PageExtractionFailed, ExtractionErrorCode::Internal,
format!("A page of the document could not be read: {e}"), format!("A page of the document could not be read: {e}"),
).into())); ).into()));
return; return;
@ -1071,10 +1078,9 @@ async fn stream_document(file_path: &str, extract_images: bool, stream_id: &str)
Ok(content) => content, Ok(content) => content,
Err(e) => { Err(e) => {
error!("Page {page_number} of the document '{path:?}' could not be converted: {e}", page_number = page.page_number); error!("Page {page_number} of the document '{path:?}' could not be converted: {e}", page_number = page.page_number);
let _ = tx.blocking_send(Err(ExtractionError::on_page( let _ = tx.blocking_send(Err(ExtractionError::new(
ExtractionErrorCode::PageExtractionFailed, ExtractionErrorCode::Internal,
format!("Page {page_number} of the document could not be converted: {e}", page_number = page.page_number), format!("Page {page_number} of the document could not be converted: {e}", page_number = page.page_number),
page.page_number,
).into())); ).into()));
return; return;
}, },