Skip to content

Commit

Permalink
Avoid pipe to get original error code (#288)
Browse files Browse the repository at this point in the history
* Adjust ocrMyPdf command
* Ensure error code of ocrMyPdf command is returned
* Fixes #259
  • Loading branch information
R0Wi authored Dec 24, 2024
1 parent bd5e2a4 commit cd83f60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/OcrProcessors/OcrMyPdfBasedProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(ICommand $command, LoggerInterface $logger, ISidecar
}

public function ocrFile(File $file, WorkflowSettings $settings, GlobalSettings $globalSettings): OcrProcessorResult {
$commandStr = 'ocrmypdf ' . $this->getCommandlineArgs($settings, $globalSettings) . ' - - | cat';
$commandStr = 'ocrmypdf ' . $this->getCommandlineArgs($settings, $globalSettings) . ' - - || exit $? ; cat';

$inputFileContent = $file->getContent();

Expand Down
16 changes: 8 additions & 8 deletions tests/Unit/OcrProcessors/PdfOcrProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function testThrowsErrorIfOcrFileWasEmpty() {
public function testLanguageSettingsAreSetCorrectly() {
$this->command->expects($this->once())
->method('setCommand')
->with('ocrmypdf -q --skip-text -l deu+eng - - | cat');
->with('ocrmypdf -q --skip-text -l deu+eng - - || exit $? ; cat');
$this->command->expects($this->once())
->method('execute')
->willReturn(true);
Expand All @@ -202,7 +202,7 @@ public function testLanguageSettingsAreSetCorrectly() {
public function testRemoveBackgroundFlagIsSetCorrectly() {
$this->command->expects($this->once())
->method('setCommand')
->with('ocrmypdf -q --skip-text --remove-background - - | cat');
->with('ocrmypdf -q --skip-text --remove-background - - || exit $? ; cat');
$this->command->expects($this->once())
->method('execute')
->willReturn(true);
Expand All @@ -217,7 +217,7 @@ public function testRemoveBackgroundFlagIsSetCorrectly() {
public function testProcessorCountIsNotSetIfGlobalSettingsDoesNotContainProcessorCount() {
$this->command->expects($this->once())
->method('setCommand')
->with('ocrmypdf -q --skip-text - - | cat');
->with('ocrmypdf -q --skip-text - - || exit $? ; cat');
$this->command->expects($this->once())
->method('execute')
->willReturn(true);
Expand All @@ -232,7 +232,7 @@ public function testProcessorCountIsNotSetIfGlobalSettingsDoesNotContainProcesso
public function testProcessorCountIsSetCorrectlyFromGobalSettings() {
$this->command->expects($this->once())
->method('setCommand')
->with('ocrmypdf -q --skip-text -j 42 - - | cat');
->with('ocrmypdf -q --skip-text -j 42 - - || exit $? ; cat');
$this->command->expects($this->once())
->method('execute')
->willReturn(true);
Expand Down Expand Up @@ -288,7 +288,7 @@ public function testDoesNotLogInfoIfSidecarFileContentWasNotEmpty() {
public function testAppliesSidecarParameterIfSidecarFileCanBeCreated() {
$this->command->expects($this->once())
->method('setCommand')
->with('ocrmypdf -q --skip-text --sidecar /tmp/sidecar.txt - - | cat');
->with('ocrmypdf -q --skip-text --sidecar /tmp/sidecar.txt - - || exit $? ; cat');
$this->command->expects($this->once())
->method('execute')
->willReturn(true);
Expand All @@ -312,7 +312,7 @@ public function testAppliesSidecarParameterIfSidecarFileCanBeCreated() {
public function testAppliesOcrModeParameter(int $simulatedOcrMode, string $expectedOcrMyPdfFlag) {
$this->command->expects($this->once())
->method('setCommand')
->with('ocrmypdf -q' . $expectedOcrMyPdfFlag . '--sidecar /tmp/sidecar.txt - - | cat');
->with('ocrmypdf -q' . $expectedOcrMyPdfFlag . '--sidecar /tmp/sidecar.txt - - || exit $? ; cat');
$this->command->expects($this->once())
->method('execute')
->willReturn(true);
Expand All @@ -333,7 +333,7 @@ public function testAppliesOcrModeParameter(int $simulatedOcrMode, string $expec
public function testRemoveBackgroundIsNotAppliedIfOcrModeIsRedoOcr() {
$this->command->expects($this->once())
->method('setCommand')
->with('ocrmypdf -q --redo-ocr --sidecar /tmp/sidecar.txt - - | cat');
->with('ocrmypdf -q --redo-ocr --sidecar /tmp/sidecar.txt - - || exit $? ; cat');
$this->command->expects($this->once())
->method('execute')
->willReturn(true);
Expand All @@ -359,7 +359,7 @@ public function testRemoveBackgroundIsNotAppliedIfOcrModeIsRedoOcr() {
public function testAppliesCustomCliArgsCorrectly() {
$this->command->expects($this->once())
->method('setCommand')
->with('ocrmypdf -q --skip-text --sidecar /tmp/sidecar.txt --output-type pdf - - | cat');
->with('ocrmypdf -q --skip-text --sidecar /tmp/sidecar.txt --output-type pdf - - || exit $? ; cat');
$this->command->expects($this->once())
->method('execute')
->willReturn(true);
Expand Down

0 comments on commit cd83f60

Please sign in to comment.