Skip to content

Commit

Permalink
catch exceptions while reparsing, show warning message & skip post
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 authored and n-peugnet committed May 3, 2023
1 parent adf7f69 commit a5bf4dc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Console/ReparseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ protected function fire()
$changed = 0;
foreach ($posts as $post) {
assert($post instanceof Post);
$src = $this->formatter->unparse($post->content, $post);
$user = is_null($post->editedUser) ? $post->user : $post->editedUser;
$content = $this->formatter->parse($src, $post, $user);
try {
$src = $this->formatter->unparse($post->content, $post);
$user = is_null($post->editedUser) ? $post->user : $post->editedUser;
$content = $this->formatter->parse($src, $post, $user);
} catch (\Throwable $exception) {
$io->warning("Error occurred while processing post with ID $post->id - reparsing was skipped:\n$exception\n");
continue;
}
if ($post->content != $content) {
$post->content = $content;
$post->save();
Expand Down

0 comments on commit a5bf4dc

Please sign in to comment.