Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch expected exception in event handler #5497

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Listeners/BeforeNodeWrittenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace OCA\Text\Listeners;

use OCA\Text\Exception\DocumentHasUnsavedChangesException;
use OCA\Text\Service\DocumentService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand All @@ -49,7 +50,11 @@ public function handle(Event $event): void {
if ($node instanceof File && $node->getMimeType() === 'text/markdown') {
if (!$this->documentService->isSaveFromText()) {
// Reset document session to avoid manual conflict resolution if there's no unsaved steps
$this->documentService->resetDocument($node->getId());
try {
$this->documentService->resetDocument($node->getId());
} catch (DocumentHasUnsavedChangesException) {
// Do not throw during event handling in this is expected to happen
}
}
}
}
Expand Down
Loading