Skip to content

Commit

Permalink
feat: add moonraker init component check with warning (mainsail-crew#…
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou authored and 4rnoP committed Dec 13, 2023
1 parent 5ef6164 commit 1f7ae9b
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
"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."
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"MoonrakerWarnings": {
"MoonrakerComponent": "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."
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/webSocketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
41 changes: 41 additions & 0 deletions src/store/gui/notifications/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const getters: GetterTree<GuiNotificationState, any> = {
// moonraker failed components
notifications = notifications.concat(getters['getNotificationsMoonrakerFailedComponents'])

// moonraker failed init components
notifications = notifications.concat(getters['getNotificationsMoonrakerFailedInitComponents'])

// klipper warnings
notifications = notifications.concat(getters['getNotificationsKlipperWarnings'])

Expand Down Expand Up @@ -224,6 +227,44 @@ export const getters: GetterTree<GuiNotificationState, any> = {
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[] = []

Expand Down
5 changes: 5 additions & 0 deletions src/store/server/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,9 @@ export const actions: ActionTree<ServerState, RootState> = {
serviceStateChanged({ commit }, payload) {
commit('updateServiceState', payload)
},

addFailedInitComponent({ commit }, payload) {
commit('removeComponent', payload)
commit('addFailedInitComponent', payload)
},
}
1 change: 1 addition & 0 deletions src/store/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const getDefaultState = (): ServerState => {
klippy_message: '',
components: [],
failed_components: [],
failed_init_components: [],
warnings: [],
registered_directories: [],
events: [],
Expand Down
17 changes: 17 additions & 0 deletions src/store/server/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,21 @@ export const mutations: MutationTree<ServerState> = {

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)
},

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)
},
}
1 change: 1 addition & 0 deletions src/store/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
6 changes: 6 additions & 0 deletions src/store/socket/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,16 @@ export const actions: ActionTree<SocketState, RootState> = {
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)
},
Expand Down
18 changes: 18 additions & 0 deletions src/store/socket/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,22 @@ export const mutations: MutationTree<SocketState> = {
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)
},
}

0 comments on commit 1f7ae9b

Please sign in to comment.