From 2b5068de21b5d9e5614e003ce0e4707c734970c9 Mon Sep 17 00:00:00 2001 From: Maksim Eltyshev Date: Sat, 30 Aug 2025 23:43:04 +0200 Subject: [PATCH] fix: Handle saga watcher errors gracefully --- client/src/sagas/core/index.js | 5 +++-- client/src/sagas/login/index.js | 5 +++-- client/src/sagas/run-watchers.js | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 client/src/sagas/run-watchers.js diff --git a/client/src/sagas/core/index.js b/client/src/sagas/core/index.js index e67e412c..2084e07d 100755 --- a/client/src/sagas/core/index.js +++ b/client/src/sagas/core/index.js @@ -3,17 +3,18 @@ * Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md */ -import { all, apply, fork, select, take } from 'redux-saga/effects'; +import { apply, fork, select, take } from 'redux-saga/effects'; import watchers from './watchers'; import services from './services'; +import runWatchers from '../run-watchers'; import selectors from '../../selectors'; import { socket } from '../../api'; import ActionTypes from '../../constants/ActionTypes'; import Paths from '../../constants/Paths'; export default function* coreSaga() { - yield all(watchers.map((watcher) => fork(watcher))); + yield runWatchers(watchers); yield apply(socket, socket.connect); yield fork(services.initializeCore); diff --git a/client/src/sagas/login/index.js b/client/src/sagas/login/index.js index 199f0ae6..19accad3 100755 --- a/client/src/sagas/login/index.js +++ b/client/src/sagas/login/index.js @@ -3,14 +3,15 @@ * Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md */ -import { all, call, cancel, fork, take } from 'redux-saga/effects'; +import { call, cancel, fork, take } from 'redux-saga/effects'; import watchers from './watchers'; import services from './services'; +import runWatchers from '../run-watchers'; import ActionTypes from '../../constants/ActionTypes'; export default function* loginSaga() { - const watcherTasks = yield all(watchers.map((watcher) => fork(watcher))); + const watcherTasks = yield runWatchers(watchers); yield fork(services.initializeLogin); diff --git a/client/src/sagas/run-watchers.js b/client/src/sagas/run-watchers.js new file mode 100644 index 00000000..c4189a0e --- /dev/null +++ b/client/src/sagas/run-watchers.js @@ -0,0 +1,21 @@ +/*! + * Copyright (c) 2024 PLANKA Software GmbH + * Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md + */ + +import { all, call, spawn } from 'redux-saga/effects'; + +function* safeWatch(watcher) { + while (true) { + try { + yield call(watcher); + break; + } catch (error) { + console.error(error); // eslint-disable-line no-console + } + } +} + +export default function* runWatchers(watchers) { + return yield all(watchers.map((watcher) => spawn(safeWatch, watcher))); +}