summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-07-04 20:15:42 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-10 20:34:47 +0200
commit4d3156ddf1599b0d647c488f92b1a9ea4d74de7e (patch)
tree3b9adb766e4864c837e0465e59262e465012f372
parent4240f1fbfd095724bcbb0ea49cfa561c973ba6ce (diff)
downloadaerc-4d3156ddf1599b0d647c488f92b1a9ea4d74de7e.zip
aerc: fix panic when backend is unknown
A panic occurs when an unknown backend is used. This regression was introduced by commit a34be9eb36d2 ("status: use contextual ui styleset for statusline"). Before this commit, an error screen for the unknown backend was displayed. The contextual ui requires an account-specific ui config but when the backend throws an error in the constructor of the account view, the call to aerc.SelectedAccountUiConfig() panics: panic: runtime error: index out of range [0] with length 0 [recovered] panic: runtime error: index out of range [0] with length 0 goroutine 1 [running]: git.sr.ht/~rjarry/aerc/logging.PanicHandler() git.sr.ht/~rjarry/aerc/logging/panic-logger.go:47 +0x6de panic({0xa42760, 0xc000427068}) runtime/panic.go:844 +0x258 git.sr.ht/~rjarry/aerc/widgets.(*Aerc).SelectedTab(...) git.sr.ht/~rjarry/aerc/widgets/aerc.go:337 git.sr.ht/~rjarry/aerc/widgets.(*Aerc).SelectedAccount(...) git.sr.ht/~rjarry/aerc/widgets/aerc.go:313 git.sr.ht/~rjarry/aerc/widgets.(*Aerc).SelectedAccountUiConfig(0x9c99c0?) git.sr.ht/~rjarry/aerc/widgets/aerc.go:329 +0xe9 git.sr.ht/~rjarry/aerc/widgets.(*StatusLine).uiConfig(...) git.sr.ht/~rjarry/aerc/widgets/status.go:112 git.sr.ht/~rjarry/aerc/widgets.(*StatusLine).SetError(0xc00043a420, {0xc000429220, 0x1b}) git.sr.ht/~rjarry/aerc/widgets/status.go:66 +0x4d git.sr.ht/~rjarry/aerc/widgets.(*Aerc).SetError(0xa7c4d7?, {0xc000429220?, 0xc00035ec80?}) git.sr.ht/~rjarry/aerc/widgets/aerc.go:440 +0x25 git.sr.ht/~rjarry/aerc/widgets.NewAccountView(0xc000502000, 0xc0002b8000, 0xc000440700, 0xc000098960, {0xb72d58?, 0xc000502000}, 0xc00042c3c0) git.sr.ht/~rjarry/aerc/widgets/account.go:75 +0xafa git.sr.ht/~rjarry/aerc/widgets.NewAerc(0xc0002b8000, 0xc000098960, {0xb73300?, 0xc0004380f0}, 0xc000420108, 0xc000430630, {0xb71580?, 0xfae9a0}, 0x2?) git.sr.ht/~rjarry/aerc/widgets/aerc.go:92 +0x8e5 main.main() git.sr.ht/~rjarry/aerc/aerc.go:176 +0x5ff This can be reproduced by adding the following as the first (!) backend to your accounts.conf: [test] source = test from = test Expected behavior would be to see the error screen with the "Unknown Backend" text. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--widgets/aerc.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 3621201..fffbf02 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -334,7 +334,10 @@ func (aerc *Aerc) SelectedAccountUiConfig() *config.UIConfig {
}
func (aerc *Aerc) SelectedTab() ui.Drawable {
- return aerc.tabs.Tabs[aerc.tabs.Selected].Content
+ if aerc.NumTabs() == 0 || aerc.SelectedTabIndex() >= aerc.NumTabs() {
+ return nil
+ }
+ return aerc.tabs.Tabs[aerc.SelectedTabIndex()].Content
}
func (aerc *Aerc) SelectedTabIndex() int {