{"record":{"id":"a5057f8e85f9656a","repo":"gofiber/fiber","slug":"fiber-service-at-index-d-is-nil-a5057f","errorCode":null,"errorMessage":"fiber: service at index %d is nil","messagePattern":"fiber: service at index (.+?) is nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"app.go","lineNumber":733,"sourceCode":"\n\t// Define hooks\n\tapp.hooks = newHooks(app)\n\n\t// Define mountFields\n\tapp.mountFields = newMountFields(app)\n\n\t// Define state\n\tapp.state = newState()\n\n\t// Override config if provided\n\tif len(config) > 0 {\n\t\tapp.config = config[0]\n\t}\n\n\t// Initialize configured before defaults are set\n\tapp.configured = app.config\n\tif err := app.validateConfiguredServices(); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Override default values\n\tif app.config.BodyLimit <= 0 {\n\t\tapp.config.BodyLimit = DefaultBodyLimit\n\t}\n\tif app.config.MaxRanges <= 0 {\n\t\tapp.config.MaxRanges = DefaultMaxRanges\n\t}\n\tif app.config.Concurrency <= 0 {\n\t\tapp.config.Concurrency = DefaultConcurrency\n\t}\n\tif app.config.ReadBufferSize <= 0 {\n\t\tapp.config.ReadBufferSize = DefaultReadBufferSize\n\t}\n\tif app.config.WriteBufferSize <= 0 {\n\t\tapp.config.WriteBufferSize = DefaultWriteBufferSize\n\t}","sourceCodeStart":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/app.go#L715-L751","documentation":"During fiber.New(Config{...}), validateConfiguredServices iterates Config.Services and returns this error if any entry is nil; fiber.New then panics on that error. Services are user-supplied background workers (DB pools, clients) that Fiber starts/stops with the app, and a nil slot is always a caller bug.","triggerScenarios":"Calling fiber.New(fiber.Config{Services: []fiber.Service{nil, someSvc}}) or building the Services slice conditionally and appending nil when a constructor fails.","commonSituations":"Constructing the Services slice with optional entries where one is unset; refactor that introduces a nil-producing factory; conditional registration like if cond { services = append(services, nil) }.","solutions":["Audit the Config.Services slice construction and drop nil entries before passing to fiber.New.","Replace any nil service with a real initialized instance or omit it.","Add a helper that filters nils: slices.DeleteFunc(services, func(s fiber.Service) bool { return s == nil }).","Make service factories return an error instead of nil so the failure is explicit."],"exampleFix":"// before\nservices := []fiber.Service{dbPool, maybeNilClient}\napp := fiber.New(fiber.Config{Services: services})\n\n// after\nservices := []fiber.Service{}\nif dbPool != nil { services = append(services, dbPool) }\nif maybeNilClient != nil { services = append(services, maybeNilClient) }\napp := fiber.New(fiber.Config{Services: services})","handlingStrategy":"validation","validationCode":"// Filter nil services before constructing the app\nfunc buildServices(svcs []fiber.Service) []fiber.Service {\n    out := svcs[:0:0]\n    for _, s := range svcs {\n        if s == nil { continue }\n        out = append(out, s)\n    }\n    return out\n}","typeGuard":null,"tryCatchPattern":"// Defer-recover around fiber.New in bootstrap to convert panic to error\nfunc newApp(cfg fiber.Config) (app *fiber.App, err error) {\n    defer func() {\n        if r := recover(); r != nil { err = fmt.Errorf(\"fiber.New: %v\", r) }\n    }()\n    app = fiber.New(cfg)\n    return app, nil\n}","preventionTips":["Make service factories return (Service, error), never nil.","Write a startup test that constructs the app config and asserts no panic.","Keep Config.Services construction in one place to audit easily."],"tags":["services","config","nil","startup"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}