Skip to content

Commit

Permalink
Pass on error code in checkProcessStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Lei committed Dec 13, 2018
1 parent b093df9 commit 07d85f5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ tfoot { display:table-footer-group; }

*A*: Please, check your `wkhtmltopdf` version. It is recommended to use at least `0.12.2.1` and what is important - starting from `wkhtmltopdf >= 0.12.2` it doesn't require X server or emulation anymore. You can download new version from http://wkhtmltopdf.org/downloads.html or install via composer for Linux servers as stated in [README](https://github.com/KnpLabs/snappy#wkhtmltopdf-binary-as-composer-dependencies). If there is no possibility to update `wkhtmltopdf`, please check http://stackoverflow.com/questions/9604625/wkhtmltopdf-cannot-connect-to-x-server

###### *Q*: PDF generation failed with wkhtmltopdf returning error code 1 due to ContentNotFoundError, how do I deal with that?
*A*: This is a known problem with wkhtmltopdf. Several issues has been raised: [issue 1855](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1855), [issue 2051](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2051). To catch that error, `generate` method will throw a `RuntimeException` with error code equals to the error code returned with wkhtmltopdf, catch this exception and check for the error code and then deal with this exception in appropriate ways.

###### *Q*: My PDF is always generated for a small screen resolution\I always receive a mobile version.

Expand Down
2 changes: 1 addition & 1 deletion src/Knp/Snappy/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ protected function checkProcessStatus($status, $stdout, $stderr, $command)
. 'stdout: "%s"' . "\n"
. 'command: %s.',
$status, $stderr, $stdout, $command
));
), $status);
}
}

Expand Down
8 changes: 6 additions & 2 deletions test/Knp/Snappy/AbstractGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,12 @@ public function testCheckProcessStatus()
$this->fail('1 status means failure, but no stderr content');
}

$this->expectException(\RuntimeException::class);
$r->invokeArgs($media, [1, '', 'Could not connect to X', 'the command']);
try {
$r->invokeArgs($media, [1, '', 'Could not connect to X', 'the command']);
$this->fail('1 status means failure');
} catch (\RuntimeException $e) {
$this->assertEquals(1, $e->getCode(), 'Execption thrown by checkProcessStatus should pass on the error code');
}
}

/**
Expand Down

0 comments on commit 07d85f5

Please sign in to comment.