Skip to content

Commit 2045c05

Browse files
committed
fix: add nil check for config in routing mode handlers
GetConfig() can return nil config (e.g., in tests with mock controllers). Add nil guard before accessing cfg.RoutingMode to prevent panic.
1 parent a27d360 commit 2045c05

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

internal/httpapi/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ func (s *Server) writeSuccess(w http.ResponseWriter, data interface{}) {
667667
func (s *Server) handleGetStatus(w http.ResponseWriter, _ *http.Request) {
668668
// Get routing mode from config
669669
routingMode := config.RoutingModeRetrieveTools
670-
if cfg, err := s.controller.GetConfig(); err == nil && cfg.RoutingMode != "" {
670+
if cfg, err := s.controller.GetConfig(); err == nil && cfg != nil && cfg.RoutingMode != "" {
671671
routingMode = cfg.RoutingMode
672672
}
673673

@@ -695,7 +695,7 @@ func (s *Server) handleGetStatus(w http.ResponseWriter, _ *http.Request) {
695695
// @Router /api/v1/routing [get]
696696
func (s *Server) handleGetRouting(w http.ResponseWriter, _ *http.Request) {
697697
routingMode := config.RoutingModeRetrieveTools
698-
if cfg, err := s.controller.GetConfig(); err == nil && cfg.RoutingMode != "" {
698+
if cfg, err := s.controller.GetConfig(); err == nil && cfg != nil && cfg.RoutingMode != "" {
699699
routingMode = cfg.RoutingMode
700700
}
701701

0 commit comments

Comments
 (0)