From ecddd8346676e11ff6f277cf37f49e0a8504083c Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 9 Dec 2023 11:21:30 +0100 Subject: [PATCH 1/4] feat: add moonraker init component check with warning Signed-off-by: Stefan Dej --- src/locales/en.json | 2 ++ src/plugins/webSocketClient.ts | 17 +++++++++-- src/store/gui/notifications/getters.ts | 41 ++++++++++++++++++++++++++ src/store/server/actions.ts | 4 +++ src/store/server/index.ts | 1 + src/store/server/mutations.ts | 7 +++++ src/store/server/types.ts | 1 + src/store/socket/actions.ts | 6 ++++ src/store/socket/mutations.ts | 18 +++++++++++ 9 files changed, 94 insertions(+), 3 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 8388d465f..1253f7b7f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -17,7 +17,9 @@ }, "MoonrakerWarnings": { "MoonrakerComponent": "Moonraker: {component}", + "MoonrakerInitComponent": "Init. Moonraker: {component}", "MoonrakerFailedComponentDescription": "An error was detected while loading the moonraker component '{component}'. Please check the log file and fix the issue.", + "MoonrakerFailedInitComponentDescription": "An error was detected during initialization the moonraker component '{component}'. Please check the log file and fix the issue.", "MoonrakerWarning": "Moonraker warning", "UnparsedConfigOption": "Unparsed config option '{option}: {value}' detected in section [{section}]. This may be an option no longer available or could be the result of a module that failed to load. In the future this will result in a startup error.", "UnparsedConfigSection": "Unparsed config section [{section}] detected. This may be the result of a component that failed to load. In the future this will result in a startup error." diff --git a/src/plugins/webSocketClient.ts b/src/plugins/webSocketClient.ts index b79d5cc35..ec5a34f84 100644 --- a/src/plugins/webSocketClient.ts +++ b/src/plugins/webSocketClient.ts @@ -61,10 +61,21 @@ export class WebSocketClient { // report error messages if (data.error?.message) { - if (data.error?.message !== 'Klippy Disconnected') + // only report errors, if not disconnected and no init component + if (data.error?.message !== 'Klippy Disconnected' && !wait?.action?.startsWith('server/')) { window.console.error(`Response Error: ${data.error.message} (${wait?.action ?? 'no action'})`) - - if (wait?.id) this.removeWaitById(wait.id) + } + + if (wait?.id) { + if (wait.action?.startsWith('server/')) { + const component = wait.action.replace('server/', '').split('/')[0] + window.console.error(`init server component ${component} failed`) + this.store?.dispatch('server/addFailedInitComponent', component) + this.store?.dispatch('socket/removeInitComponent', `server/${component}/`) + } + + this.removeWaitById(wait.id) + } return } diff --git a/src/store/gui/notifications/getters.ts b/src/store/gui/notifications/getters.ts index a4072f186..2384c1d90 100644 --- a/src/store/gui/notifications/getters.ts +++ b/src/store/gui/notifications/getters.ts @@ -28,6 +28,9 @@ export const getters: GetterTree = { // moonraker failed components notifications = notifications.concat(getters['getNotificationsMoonrakerFailedComponents']) + // moonraker failed init components + notifications = notifications.concat(getters['getNotificationsMoonrakerFailedInitComponents']) + // klipper warnings notifications = notifications.concat(getters['getNotificationsKlipperWarnings']) @@ -224,6 +227,44 @@ export const getters: GetterTree = { return notifications }, + getNotificationsMoonrakerFailedInitComponents: (state, getters, rootState, rootGetters) => { + const notifications: GuiNotificationStateEntry[] = [] + + let failedInitCompontents = rootState.server.failed_init_components ?? [] + if (failedInitCompontents.length) { + const date = rootState.server.system_boot_at ?? new Date() + + // get all dismissed failed components and convert it to a string[] + const flagDismisses = rootGetters['gui/notifications/getDismissByCategory']( + 'moonrakerFailedInitComponent' + ).map((dismiss: GuiNotificationStateDismissEntry) => { + return dismiss.id + }) + + // filter all dismissed failed init components + failedInitCompontents = failedInitCompontents.filter( + (component: string) => !flagDismisses.includes(component) + ) + + failedInitCompontents.forEach((component: string) => { + notifications.push({ + id: `moonrakerFailedInitComponent/${component}`, + priority: 'high', + title: i18n + .t('App.Notifications.MoonrakerWarnings.MoonrakerInitComponent', { component }) + .toString(), + description: i18n + .t('App.Notifications.MoonrakerWarnings.MoonrakerFailedInitComponentDescription', { component }) + .toString(), + date, + dismissed: false, + } as GuiNotificationStateEntry) + }) + } + + return notifications + }, + getNotificationsKlipperWarnings: (state, getters, rootState, rootGetters) => { const notifications: GuiNotificationStateEntry[] = [] diff --git a/src/store/server/actions.ts b/src/store/server/actions.ts index b5a915735..3746087b6 100644 --- a/src/store/server/actions.ts +++ b/src/store/server/actions.ts @@ -292,4 +292,8 @@ export const actions: ActionTree = { serviceStateChanged({ commit }, payload) { commit('updateServiceState', payload) }, + + addFailedInitComponent({ commit }, payload) { + commit('addFailedInitComponent', payload) + }, } diff --git a/src/store/server/index.ts b/src/store/server/index.ts index 643e9ce4c..1fde111a3 100644 --- a/src/store/server/index.ts +++ b/src/store/server/index.ts @@ -23,6 +23,7 @@ export const getDefaultState = (): ServerState => { klippy_message: '', components: [], failed_components: [], + failed_init_components: [], warnings: [], registered_directories: [], events: [], diff --git a/src/store/server/mutations.ts b/src/store/server/mutations.ts index d31d00693..7e2f4e5b8 100644 --- a/src/store/server/mutations.ts +++ b/src/store/server/mutations.ts @@ -160,4 +160,11 @@ export const mutations: MutationTree = { if (state.system_info?.service_state) Vue.set(state.system_info.service_state, name, payload[name]) }, + + addFailedInitComponent(state, payload) { + const failed_init_components = state.failed_init_components + if (!failed_init_components.includes(payload)) failed_init_components.push(payload) + + Vue.set(state, 'failed_init_components', failed_init_components) + }, } diff --git a/src/store/server/types.ts b/src/store/server/types.ts index 03c5f0c11..69d6fe399 100644 --- a/src/store/server/types.ts +++ b/src/store/server/types.ts @@ -11,6 +11,7 @@ export interface ServerState { klippy_message: string components: string[] failed_components: string[] + failed_init_components: string[] warnings: string[] registered_directories: string[] events: ServerStateEvent[] diff --git a/src/store/socket/actions.ts b/src/store/socket/actions.ts index a58a016d1..30f8cf7c8 100644 --- a/src/store/socket/actions.ts +++ b/src/store/socket/actions.ts @@ -153,10 +153,16 @@ export const actions: ActionTree = { commit('addInitModule', payload) }, + // remove only one module from init component like 'server/spoolman/getActiveSpoolId' removeInitModule({ commit }, payload: string) { commit('removeInitModule', payload) }, + // remove a complete init component like 'server/spoolman' + removeInitComponent({ commit }, payload: string) { + commit('removeInitComponent', payload) + }, + reportDebug(_, payload) { window.console.log(payload) }, diff --git a/src/store/socket/mutations.ts b/src/store/socket/mutations.ts index 61972f40f..9399eb169 100644 --- a/src/store/socket/mutations.ts +++ b/src/store/socket/mutations.ts @@ -61,4 +61,22 @@ export const mutations: MutationTree = { list.splice(index, 1) Vue.set(state, 'initializationList', list) }, + + removeInitComponent(state, payload) { + const list = [...state.initializationList] + + // remove all components witch starts with payload + const indexes = list.reduce((acc: number[], item, index) => { + if (item.startsWith(payload)) acc.push(index) + return acc + }, []) + + // stop if no items found + if (!indexes.length) return + + // remove all items + indexes.forEach((index) => list.splice(index, 1)) + + Vue.set(state, 'initializationList', list) + }, } From 9857b98f44a50b7545955e9239c9b68fdd7f5c04 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 9 Dec 2023 11:23:11 +0100 Subject: [PATCH 2/4] locale(de): add german locale Signed-off-by: Stefan Dej --- src/locales/de.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/locales/de.json b/src/locales/de.json index 44326dbd9..2ffc75a3f 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -17,7 +17,9 @@ }, "MoonrakerWarnings": { "MoonrakerComponent": "Moonraker: {component}", - "MoonrakerFailedComponentDescription": "Beim Laden der Moonraker-Komponenten wurde ein Fehler festgestellt. Bitte prüfe die Logdatei und behebe das Problem.", + "MoonrakerInitComponent": "Init. Moonraker: {component}", + "MoonrakerFailedComponentDescription": "Beim Laden der Moonraker-Komponente '{component}' wurde ein Fehler festgestellt. Bitte prüfe die Logdatei und behebe das Problem.", + "MoonrakerFailedInitComponentDescription": "Beim Initialisieren der Moonraker-Komponente '{component}' wurde ein Fehler festgestellt. Bitte prüfe die Logdatei und behebe das Problem.", "MoonrakerWarning": "Moonraker Warnung", "UnparsedConfigOption": "Nicht erkannte Config-Option '{option}: {value}' in Abschnitt [{section}] entdeckt. Dies kann eine Option sein, die nicht mehr verfügbar ist, oder das Ergebnis eines Moduls sein, das nicht geladen werden konnte. In Zukunft wird dies zu einem Startfehler führen.", "UnparsedConfigSection": "Nicht erkannter Config-Abschnitt [{section}] gefunden. Dies kann das Ergebnis einer Komponente sein, die nicht geladen werden konnte. In Zukunft wird dies zu einem Startfehler führen." From 151f865a389cc54351fc5cfd1c447a08177b0103 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 9 Dec 2023 14:07:00 +0100 Subject: [PATCH 3/4] style: fix some linter issues in locale files Signed-off-by: Stefan Dej --- src/locales/de.json | 2 +- src/locales/en.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/locales/de.json b/src/locales/de.json index 2ffc75a3f..ecd48bd23 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -17,9 +17,9 @@ }, "MoonrakerWarnings": { "MoonrakerComponent": "Moonraker: {component}", - "MoonrakerInitComponent": "Init. Moonraker: {component}", "MoonrakerFailedComponentDescription": "Beim Laden der Moonraker-Komponente '{component}' wurde ein Fehler festgestellt. Bitte prüfe die Logdatei und behebe das Problem.", "MoonrakerFailedInitComponentDescription": "Beim Initialisieren der Moonraker-Komponente '{component}' wurde ein Fehler festgestellt. Bitte prüfe die Logdatei und behebe das Problem.", + "MoonrakerInitComponent": "Init. Moonraker: {component}", "MoonrakerWarning": "Moonraker Warnung", "UnparsedConfigOption": "Nicht erkannte Config-Option '{option}: {value}' in Abschnitt [{section}] entdeckt. Dies kann eine Option sein, die nicht mehr verfügbar ist, oder das Ergebnis eines Moduls sein, das nicht geladen werden konnte. In Zukunft wird dies zu einem Startfehler führen.", "UnparsedConfigSection": "Nicht erkannter Config-Abschnitt [{section}] gefunden. Dies kann das Ergebnis einer Komponente sein, die nicht geladen werden konnte. In Zukunft wird dies zu einem Startfehler führen." diff --git a/src/locales/en.json b/src/locales/en.json index 1253f7b7f..3df757e71 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -17,9 +17,9 @@ }, "MoonrakerWarnings": { "MoonrakerComponent": "Moonraker: {component}", - "MoonrakerInitComponent": "Init. Moonraker: {component}", "MoonrakerFailedComponentDescription": "An error was detected while loading the moonraker component '{component}'. Please check the log file and fix the issue.", "MoonrakerFailedInitComponentDescription": "An error was detected during initialization the moonraker component '{component}'. Please check the log file and fix the issue.", + "MoonrakerInitComponent": "Init. Moonraker: {component}", "MoonrakerWarning": "Moonraker warning", "UnparsedConfigOption": "Unparsed config option '{option}: {value}' detected in section [{section}]. This may be an option no longer available or could be the result of a module that failed to load. In the future this will result in a startup error.", "UnparsedConfigSection": "Unparsed config section [{section}] detected. This may be the result of a component that failed to load. In the future this will result in a startup error." From 4606c3e4e87f009a86a8f086a25e1e2dab5e24d2 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 10 Dec 2023 12:34:58 +0100 Subject: [PATCH 4/4] fix: disable failed init components Signed-off-by: Stefan Dej --- src/store/server/actions.ts | 1 + src/store/server/mutations.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/store/server/actions.ts b/src/store/server/actions.ts index 3746087b6..93aeb4ce3 100644 --- a/src/store/server/actions.ts +++ b/src/store/server/actions.ts @@ -294,6 +294,7 @@ export const actions: ActionTree = { }, addFailedInitComponent({ commit }, payload) { + commit('removeComponent', payload) commit('addFailedInitComponent', payload) }, } diff --git a/src/store/server/mutations.ts b/src/store/server/mutations.ts index 7e2f4e5b8..da2777490 100644 --- a/src/store/server/mutations.ts +++ b/src/store/server/mutations.ts @@ -167,4 +167,14 @@ export const mutations: MutationTree = { Vue.set(state, 'failed_init_components', failed_init_components) }, + + removeComponent(state, payload) { + const components = state.components + const index = components.indexOf(payload) + + if (index === -1) return + + components.splice(index, 1) + Vue.set(state, 'components', components) + }, }