@@ -299,8 +299,20 @@ fn parsePdf(input_path: [*:0]const u8, output_path: [*:0]const u8, result: *Pars
299299
300300 if (c .poppler_page_get_text (page )) | text_ptr | {
301301 const text = std .mem .span (text_ptr );
302- out_file .writeAll (text ) catch {};
303- out_file .writeAll ("\n " ) catch {};
302+ out_file .writeAll (text ) catch | err | {
303+ std .log .err ("PDF output write failed on page {d}: {s}" , .{ i , @errorName (err ) });
304+ copyToFixed (256 , & result .error_msg , "Failed writing extracted PDF text to output file" );
305+ result .status = 1 ;
306+ c .g_free (text_ptr );
307+ return ;
308+ };
309+ out_file .writeAll ("\n " ) catch | err | {
310+ std .log .err ("PDF output newline write failed on page {d}: {s}" , .{ i , @errorName (err ) });
311+ copyToFixed (256 , & result .error_msg , "Failed writing extracted PDF text to output file" );
312+ result .status = 1 ;
313+ c .g_free (text_ptr );
314+ return ;
315+ };
304316 total_chars += @intCast (text .len );
305317 total_words += countWords (text );
306318 c .g_free (text_ptr );
@@ -444,7 +456,12 @@ fn parseImage(input_path: [*:0]const u8, output_path: [*:0]const u8, state: *Han
444456 return ;
445457 };
446458 defer out_file .close ();
447- out_file .writeAll (ocr_text ) catch {};
459+ out_file .writeAll (ocr_text ) catch | err | {
460+ std .log .err ("Image OCR output write failed: {s}" , .{@errorName (err )});
461+ copyToFixed (256 , & result .error_msg , "Failed writing OCR text to output file" );
462+ result .status = 1 ;
463+ return ;
464+ };
448465
449466 result .char_count = @intCast (ocr_text .len );
450467 result .word_count = countWords (ocr_text );
@@ -516,7 +533,12 @@ fn parseAudio(input_path: [*:0]const u8, output_path: [*:0]const u8, result: *Pa
516533 std .mem .sliceTo (& result .title , 0 ),
517534 std .mem .sliceTo (& result .author , 0 ),
518535 }) catch & buf ;
519- out_file .writeAll (written ) catch {};
536+ out_file .writeAll (written ) catch | err | {
537+ std .log .err ("Audio metadata output write failed: {s}" , .{@errorName (err )});
538+ copyToFixed (256 , & result .error_msg , "Failed writing audio metadata to output file" );
539+ result .status = 1 ;
540+ return ;
541+ };
520542
521543 // MIME detection
522544 const path_str = std .mem .span (input_path );
@@ -593,7 +615,12 @@ fn parseVideo(input_path: [*:0]const u8, output_path: [*:0]const u8, result: *Pa
593615 sub_count ,
594616 std .mem .sliceTo (& result .title , 0 ),
595617 }) catch & buf ;
596- out_file .writeAll (written ) catch {};
618+ out_file .writeAll (written ) catch | err | {
619+ std .log .err ("Video metadata output write failed: {s}" , .{@errorName (err )});
620+ copyToFixed (256 , & result .error_msg , "Failed writing video metadata to output file" );
621+ result .status = 1 ;
622+ return ;
623+ };
597624
598625 // MIME
599626 const path_str = std .mem .span (input_path );
@@ -665,7 +692,10 @@ fn extractXmlText(node: *c.xmlNode, file: std.fs.File, chars: *i64, words: *i64)
665692 if (n .type == c .XML_TEXT_NODE or n .type == c .XML_CDATA_SECTION_NODE ) {
666693 if (n .content ) | content | {
667694 const text = std .mem .span (content );
668- file .writeAll (text ) catch {};
695+ file .writeAll (text ) catch | err | {
696+ std .log .err ("EPUB XML text output write failed: {s}" , .{@errorName (err )});
697+ return ; // Stop traversal — output file is in an inconsistent state
698+ };
669699 chars .* += @intCast (text .len );
670700 words .* += countWords (text );
671701 }
@@ -729,7 +759,12 @@ fn parseGeo(input_path: [*:0]const u8, output_path: [*:0]const u8, result: *Pars
729759 gt [5 ],
730760 proj_str ,
731761 }) catch & buf ;
732- out_file .writeAll (written ) catch {};
762+ out_file .writeAll (written ) catch | err | {
763+ std .log .err ("Geospatial metadata output write failed: {s}" , .{@errorName (err )});
764+ copyToFixed (256 , & result .error_msg , "Failed writing geospatial metadata to output file" );
765+ result .status = 1 ;
766+ return ;
767+ };
733768
734769 // MIME
735770 const path_str = std .mem .span (input_path );
0 commit comments