From 2b7362ae33c9d3afd961e3e4a110a7c9d9849733 Mon Sep 17 00:00:00 2001 From: Alexis Couvreur Date: Wed, 11 Sep 2024 13:23:56 -0400 Subject: [PATCH] fix(dynamic): avoid panic on nil instance For some yet unknown reasons, some instances are returned as nil. This commits adds a nil check to prevent that and logs a warning to help further debugging. Fixes #380 --- app/http/routes/strategies.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/http/routes/strategies.go b/app/http/routes/strategies.go index b699a383..a73feca3 100644 --- a/app/http/routes/strategies.go +++ b/app/http/routes/strategies.go @@ -140,8 +140,17 @@ func (s *ServeStrategy) ServeBlocking(c *gin.Context) { } func sessionStateToRenderOptionsInstanceState(sessionState *sessions.SessionState) (instances []theme.Instance) { + if sessionState == nil { + log.Warnf("sessionStateToRenderOptionsInstanceState: sessionState is nil") + return + } sessionState.Instances.Range(func(key, value any) bool { - instances = append(instances, instanceStateToRenderOptionsRequestState(value.(sessions.InstanceState).Instance)) + if value != nil { + instances = append(instances, instanceStateToRenderOptionsRequestState(value.(sessions.InstanceState).Instance)) + } else { + log.Warnf("sessionStateToRenderOptionsInstanceState: sessionState instance is nil, key: %v", key) + } + return true })