From 38b0c31adc68a10d0ea9835d5c9b5773a2ebf711 Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:48:47 +0200 Subject: [PATCH] chore(plugins): gracefully handle plugin update failure Upon an failed update, rollback to the previous version. --- server/core/lib/plugins/plugin-manager.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/core/lib/plugins/plugin-manager.ts b/server/core/lib/plugins/plugin-manager.ts index ceb44415f6be..0341593189aa 100644 --- a/server/core/lib/plugins/plugin-manager.ts +++ b/server/core/lib/plugins/plugin-manager.ts @@ -429,12 +429,19 @@ export class PluginManager implements ServerHook { // Use the latest version from DB, to not upgrade to a version that does not support our PeerTube version let version: string + const plugin = await PluginModel.loadByNpmName(toUpdate) + if (!fromDisk) { - const plugin = await PluginModel.loadByNpmName(toUpdate) version = plugin.latestVersion } - return this.install({ toInstall: toUpdate, version, fromDisk }) + try { + return this.install({ toInstall: toUpdate, version, fromDisk }) + } catch (err) { + logger.info('Reinstalling last installed version.', { err }) + + return this.install({ toInstall: toUpdate, version: plugin.version }) + } } async uninstall (options: {