Skip to content

Commit

Permalink
fix: improve installation logging
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Oct 24, 2023
1 parent 974ab1a commit 056aca4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions myparcelnl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MyParcelNL\Pdk\Facade\Installer;
use MyParcelNL\Pdk\Facade\Logger;
use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\PrestaShop\Facade\MyParcelModule;
use MyParcelNL\PrestaShop\Hooks\HasPdkCheckoutDeliveryOptionsHooks;
use MyParcelNL\PrestaShop\Hooks\HasPdkCheckoutHooks;
use MyParcelNL\PrestaShop\Hooks\HasPdkOrderGridHooks;
Expand Down Expand Up @@ -66,7 +67,7 @@ public function __construct()
$this->withErrorHandling(
[$this, 'setup'],
sprintf('Failed to instantiate %s', $this->displayName),
function (Throwable $e) {
function () {
$this->hasPdk = false;

if ($this->active) {
Expand All @@ -76,6 +77,16 @@ function (Throwable $e) {
);
}

/**
* @param bool $force_all
*
* @return bool
*/
public function enable($force_all = false): bool
{
return parent::enable($force_all) && $this->withErrorHandling([MyParcelModule::class, 'registerHooks']);
}

/**
* Redirects the "configure" button in the module list to the settings page.
*
Expand Down Expand Up @@ -211,13 +222,17 @@ private function withErrorHandling(
Logger::error("An error occurred: {$e->getMessage()}", ['exception' => $e->getTraceAsString()]);
}

$this->_errors[] = sprintf(
'<hr>%s: %s<br><br><b>Stack trace:</b><br><code>%s</code>',
$formattedMessage = sprintf(
"%s: %s\n\nStack trace:\n%s",
$message ?? 'Error',
$e->getMessage(),
str_replace("\n", '<br>', $e->getTraceAsString())
$e->getTraceAsString()
);

PrestaShopLogger::addLog($formattedMessage, PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR);

$this->_errors[] = str_replace("\n", '<br>', $formattedMessage);

if ($failureCallback) {
$failureCallback($e);
}
Expand Down

0 comments on commit 056aca4

Please sign in to comment.