From 0838f4b1ad9ea91dd5d7463285f5dbbd3bcd3ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 18 Feb 2022 12:51:55 +0100 Subject: [PATCH] Plugins: Fix importing panel modules (#45590) --- .../app/features/plugins/importPanelPlugin.ts | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/public/app/features/plugins/importPanelPlugin.ts b/public/app/features/plugins/importPanelPlugin.ts index 40d4dc3549d..ccb3bdf9251 100644 --- a/public/app/features/plugins/importPanelPlugin.ts +++ b/public/app/features/plugins/importPanelPlugin.ts @@ -28,22 +28,25 @@ export function importPanelPluginFromMeta(meta: grafanaData.PanelPluginMeta): Pr return getPanelPlugin(meta); } -async function getPanelPlugin(meta: grafanaData.PanelPluginMeta): Promise { - try { - const pluginExports = await importPluginModule(meta.module, meta.info?.version); - let plugin = pluginExports.plugin; - - if (!plugin && pluginExports.PanelCtrl) { - plugin = new grafanaData.PanelPlugin(null); - plugin.angularPanelCtrl = pluginExports.PanelCtrl; - } - - plugin.meta = meta; - - return plugin; - } catch (err) { - // TODO, maybe a different error plugin - console.warn('Error loading panel plugin: ' + meta.id, err); - return getPanelPluginLoadError(meta, err); - } +function getPanelPlugin(meta: grafanaData.PanelPluginMeta): Promise { + return importPluginModule(meta.module, meta.info?.version) + .then((pluginExports) => { + if (pluginExports.plugin) { + return pluginExports.plugin as grafanaData.PanelPlugin; + } else if (pluginExports.PanelCtrl) { + const plugin = new grafanaData.PanelPlugin(null); + plugin.angularPanelCtrl = pluginExports.PanelCtrl; + return plugin; + } + throw new Error('missing export: plugin or PanelCtrl'); + }) + .then((plugin) => { + plugin.meta = meta; + return plugin; + }) + .catch((err) => { + // TODO, maybe a different error plugin + console.warn('Error loading panel plugin: ' + meta.id, err); + return getPanelPluginLoadError(meta, err); + }); }