From 357c7c2000a6430fc5eb943da26eb7d1d4accd61 Mon Sep 17 00:00:00 2001 From: Konstantin Auffinger Date: Mon, 16 Dec 2024 17:53:55 +0100 Subject: [PATCH] fix: correct error output --- src/Markitdown.php | 4 ++-- .../MarkitdownTest/it_can_convert_from_string.snap | 9 +++++++++ tests/MarkitdownTest.php | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/.pest/snapshots/MarkitdownTest/it_can_convert_from_string.snap diff --git a/src/Markitdown.php b/src/Markitdown.php index d160925..52092ad 100755 --- a/src/Markitdown.php +++ b/src/Markitdown.php @@ -30,7 +30,7 @@ public function convert(string $filename): string ->run(); if (! $processResult->successful()) { - throw MarkitdownException::processFailed('markitdown', $processResult->output()); + throw MarkitdownException::processFailed('markitdown', $processResult->errorOutput()); } return $processResult->output(); @@ -44,7 +44,7 @@ public function convertString(string $content): string ->run(); if (! $processResult->successful()) { - throw MarkitdownException::processFailed('markitdown', $processResult->output()); + throw MarkitdownException::processFailed('markitdown', $processResult->errorOutput()); } return $processResult->output(); diff --git a/tests/.pest/snapshots/MarkitdownTest/it_can_convert_from_string.snap b/tests/.pest/snapshots/MarkitdownTest/it_can_convert_from_string.snap new file mode 100644 index 0000000..ea874a0 --- /dev/null +++ b/tests/.pest/snapshots/MarkitdownTest/it_can_convert_from_string.snap @@ -0,0 +1,9 @@ + +# Take Notes + +* To take notes, just tap here and start typing. +* Or, easily create a digital notebook for all your notes that automatically syncs across your devices, using the free OneNote app. + +## To learn more and get OneNote, visit [www.onenote.com](http://go.microsoft.com/fwlink/?LinkID=523891). + + diff --git a/tests/MarkitdownTest.php b/tests/MarkitdownTest.php index 65ebca0..aa78794 100644 --- a/tests/MarkitdownTest.php +++ b/tests/MarkitdownTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use Innobrain\Markitdown\Exceptions\MarkitdownException; use Innobrain\Markitdown\Facades\Markitdown; it('can execute markitdown', function (): void { @@ -21,3 +22,7 @@ expect($conv)->toMatchSnapshot(); }); + +it('throws exception with error output when process fails', function (): void { + Markitdown::convert('non_existent_file.docx'); +})->throws(MarkitdownException::class, 'The command `markitdown` failed with output: Traceback (most recent call last):');