on main help sign in
fix(tui): guard against panics in map member access
1bc41c8Christian Rocha
internal/tui/tui.go+37−6
@@ -209,8 +209,13 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
209 })
209 })
210 // Permissions
210 // Permissions
211 case pubsub.Event[permission.PermissionNotification]:
211 case pubsub.Event[permission.PermissionNotification]:
212+ item, ok := a.pages[a.currentPage]
213+ if !ok {
214+ return a, nil
215+ }
216+
212 // forward to page
217 // forward to page
213− updated, cmd := a.pages[a.currentPage].Update(msg)
218+ updated, cmd := item.Update(msg)
214 a.pages[a.currentPage] = updated.(util.Model)
219 a.pages[a.currentPage] = updated.(util.Model)
215 return a, cmd
220 return a, cmd
216 case pubsub.Event[permission.PermissionRequest]:
221 case pubsub.Event[permission.PermissionRequest]:
@@ -258,8 +263,13 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
258
263
259 return a, tea.Batch(cmds...)
264 return a, tea.Batch(cmds...)
260 case splash.OnboardingCompleteMsg:
265 case splash.OnboardingCompleteMsg:
266+ item, ok := a.pages[a.currentPage]
267+ if !ok {
268+ return a, nil
269+ }
270+
261 a.isConfigured = config.HasInitialDataConfig()
271 a.isConfigured = config.HasInitialDataConfig()
262− updated, pageCmd := a.pages[a.currentPage].Update(msg)
272+ updated, pageCmd := item.Update(msg)
263 a.pages[a.currentPage] = updated.(util.Model)
273 a.pages[a.currentPage] = updated.(util.Model)
264 cmds = append(cmds, pageCmd)
274 cmds = append(cmds, pageCmd)
265 return a, tea.Batch(cmds...)
275 return a, tea.Batch(cmds...)
@@ -273,7 +283,12 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
273 a.dialog = u.(dialogs.DialogCmp)
283 a.dialog = u.(dialogs.DialogCmp)
274 cmds = append(cmds, dialogCmd)
284 cmds = append(cmds, dialogCmd)
275 } else {
285 } else {
276− updated, pageCmd := a.pages[a.currentPage].Update(msg)
286+ item, ok := a.pages[a.currentPage]
287+ if !ok {
288+ return a, nil
289+ }
290+
291+ updated, pageCmd := item.Update(msg)
277 a.pages[a.currentPage] = updated.(util.Model)
292 a.pages[a.currentPage] = updated.(util.Model)
278 cmds = append(cmds, pageCmd)
293 cmds = append(cmds, pageCmd)
279 }
294 }
@@ -284,7 +299,12 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
284 a.dialog = u.(dialogs.DialogCmp)
299 a.dialog = u.(dialogs.DialogCmp)
285 cmds = append(cmds, dialogCmd)
300 cmds = append(cmds, dialogCmd)
286 } else {
301 } else {
287− updated, pageCmd := a.pages[a.currentPage].Update(msg)
302+ item, ok := a.pages[a.currentPage]
303+ if !ok {
304+ return a, nil
305+ }
306+
307+ updated, pageCmd := item.Update(msg)
288 a.pages[a.currentPage] = updated.(util.Model)
308 a.pages[a.currentPage] = updated.(util.Model)
289 cmds = append(cmds, pageCmd)
309 cmds = append(cmds, pageCmd)
290 }
310 }
@@ -292,8 +312,14 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
292 }
312 }
293 s, _ := a.status.Update(msg)
313 s, _ := a.status.Update(msg)
294 a.status = s.(status.StatusCmp)
314 a.status = s.(status.StatusCmp)
315+
295− updated, cmd := a.pages[a.currentPage].Update(msg)
316+ item, ok := a.pages[a.currentPage]
317+ if !ok {
318+ return a, nil
319+ }
320+ updated, cmd := item.Update(msg)
296 a.pages[a.currentPage] = updated.(util.Model)
321 a.pages[a.currentPage] = updated.(util.Model)
322+
297 if a.dialog.HasDialogs() {
323 if a.dialog.HasDialogs() {
298 u, dialogCmd := a.dialog.Update(msg)
324 u, dialogCmd := a.dialog.Update(msg)
299 a.dialog = u.(dialogs.DialogCmp)
325 a.dialog = u.(dialogs.DialogCmp)
@@ -411,7 +437,12 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
411 a.dialog = u.(dialogs.DialogCmp)
437 a.dialog = u.(dialogs.DialogCmp)
412 return dialogCmd
438 return dialogCmd
413 } else {
439 } else {
414− updated, cmd := a.pages[a.currentPage].Update(msg)
440+ item, ok := a.pages[a.currentPage]
441+ if !ok {
442+ return nil
443+ }
444+
445+ updated, cmd := item.Update(msg)
415 a.pages[a.currentPage] = updated.(util.Model)
446 a.pages[a.currentPage] = updated.(util.Model)
416 return cmd
447 return cmd
417 }
448 }