Skip to content

Commit

Permalink
imp: Add more context to the MailboxEmail errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marien-probesys committed Jan 10, 2025
1 parent 9b7d8b3 commit 3d65c4c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
9 changes: 9 additions & 0 deletions assets/stylesheets/utils/text.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
word-wrap: anywhere;
}

.pre--formatted {
padding: var(--space-small);

white-space: pre-wrap;

background-color: var(--color-grey3);
border-radius: var(--border-radius);
}

code {
padding: 0 0.5rem;

Expand Down
10 changes: 10 additions & 0 deletions src/Entity/MailboxEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public function getLastError(): ?string
return $this->lastError;
}

public function getLastErrorSummary(): string
{
if (!$this->lastError) {
return '';
}

$splitError = explode("\n", trim($this->lastError));
return $splitError[0];
}

public function setLastError(string $lastError): self
{
$this->lastError = $lastError;
Expand Down
5 changes: 2 additions & 3 deletions src/MessageHandler/CreateTicketsFromMailboxEmailsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ public function __invoke(CreateTicketsFromMailboxEmails $message): void
try {
$this->processMailboxEmail($mailboxEmail);
} catch (\Exception $e) {
$error = $e->getMessage();

$error = $e->getMessage() . "\n\n" . $e->getTraceAsString();
$mailboxEmail->setLastError($error);
$this->mailboxEmailRepository->save($mailboxEmail, true);

$this->logger->error("MailboxEmail #{$mailboxEmail->getId()} error: {$error}");
$this->logger->error("MailboxEmail #{$mailboxEmail->getId()} error: {$e->getMessage()}");
} finally {
$lock->release();
}
Expand Down
21 changes: 17 additions & 4 deletions templates/mailboxes/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,23 @@
</div>

<div class="cols flow">
<p class="col--extend text--error">
{{ 'mailboxes.index.emails.error' | trans }}
{{ mailboxEmail.lastError }}
</p>
<div class="col--extend">
{% if mailboxEmail.lastErrorSummary == mailboxEmail.lastError %}
<p class="text--error text--bold">
{{ 'mailboxes.index.emails.error' | trans }}
{{ mailboxEmail.lastError }}
</p>
{% else %}
<details>
<summary class="text--error text--bold">
{{ 'mailboxes.index.emails.error' | trans }}
{{ mailboxEmail.lastErrorSummary }}
</summary>

<pre class="pre--formatted">{{ mailboxEmail.lastError }}</pre>
</details>
{% endif %}
</div>

<form method="POST" action="{{ path('delete mailbox email', { uid: mailboxEmail.uid }) }}">
<input type="hidden" name="_csrf_token" value="{{ csrf_token('delete mailbox email') }}">
Expand Down

0 comments on commit 3d65c4c

Please sign in to comment.