{"record":{"id":"06a223ec208f9cf0","repo":"dagger/dagger","slug":"service-container-is-nil","errorCode":null,"errorMessage":"service container is nil","messagePattern":"service container is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/service.go","lineNumber":580,"sourceCode":"\tsrv := dagql.CurrentDagqlServer(ctx)\n\tif srv == nil {\n\t\treturn fmt.Errorf(\"failed to get dagql server\")\n\t}\n\tattachedAny, err := cacheCtr.AttachResult(ctx, clientMetadata.SessionID, srv, svc.Container)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"attach service container: %w\", err)\n\t}\n\tattached, ok := attachedAny.(dagql.ObjectResult[*Container])\n\tif !ok {\n\t\treturn fmt.Errorf(\"attach service container: expected %T, got %T\", svc.Container, attachedAny)\n\t}\n\tsvc.Container = attached\n\tif err := cacheCtr.Evaluate(ctx, svc.Container); err != nil {\n\t\treturn err\n\t}\n\tctr := svc.Container.Self()\n\tif ctr == nil {\n\t\treturn fmt.Errorf(\"service container is nil\")\n\t}\n\n\texecMD := svc.ExecMD\n\tif execMD == nil {\n\t\texecMD, err = ctr.execMeta(ctx, ContainerExecOpts{\n\t\t\tExperimentalPrivilegedNesting: svc.ExperimentalPrivilegedNesting,\n\t\t\tNoInit:                        svc.NoInit,\n\t\t}, nil, svc.ModuleContext)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t} else {\n\t\tcloned := *execMD\n\t\texecMD = &cloned\n\t}\n\n\tquery, err := CurrentQuery(ctx)\n\tif err != nil {","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/service.go#L562-L598","documentation":"After the service container is attached and evaluated, its underlying *Container self value is nil, so startContainer cannot derive exec metadata. This guards against evaluating a container that resolved to nothing.","triggerScenarios":"cacheCtr.Evaluate(ctx, svc.Container) succeeds but svc.Container.Self() returns nil — the container object exists in the dagql cache but its backing self value was never populated or was garbage-collected.","commonSituations":"A Service was constructed/serialized without a materialized container, e.g. a module returned a Service whose container came from a failed or stubbed evaluation, or internal cache eviction between attach and evaluate.","solutions":["Retry the service start","Ensure the Service comes from a real Container.AsService() call in your module code","Report to Dagger maintainers with the trace if it reproduces","Upgrade CLI/engine to align versions"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// ensure the Service is built from a materialized container\nctr := containerFrom(ctx, mod)\nsvc := ctr.WithExec([...]).AsService()","typeGuard":"func hasSelf(c dagql.ObjectResult[*Container]) bool {\n    return c != nil && c.Self() != nil\n}","tryCatchPattern":"if err := startService(ctx, svc); err != nil {\n    if err.Error() == \"service container is nil\" {\n        // rebuild the Service from a fresh container and retry\n    }\n    return err\n}","preventionTips":["Always construct Services from evaluated containers","Avoid holding Services across long sessions where cache may be evicted","Retry after rebuilding the container","Upgrade engine/CLI to matching versions"],"tags":["go","nil-pointer","internal-state"],"backgroundTag":"nil-value-where-value-required","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}