{"record":{"id":"0774e6b75ab9e5d9","repo":"Tencent/WeKnora","slug":"sandbox-docker-client-requires-a-config","errorCode":null,"errorMessage":"sandbox: docker client requires a config","messagePattern":"sandbox: docker client requires a config","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"internal/sandbox/docker_remote_client.go","lineNumber":154,"sourceCode":"\n// newDockerRemoteClientWithAPI is the seam unit tests use: it takes any\n// dockerEngineAPI, including an in-memory fake.\nfunc newDockerRemoteClientWithAPI(\n\tapi dockerEngineAPI,\n\tsettings dockerRuntimeSettings,\n) *DockerRemoteClient {\n\tadapter := &DockerRemoteClient{api: api, settings: settings}\n\tif settings.IdleTTL > 0 {\n\t\tadapter.sweeper = newDockerIdleSweeper(adapter, settings.IdleTTL)\n\t}\n\treturn adapter\n}\n\n// dockerSettingsFromConfig projects Config, applying the built-in defaults for\n// every value the workspace config leaves unset.\nfunc dockerSettingsFromConfig(cfg *Config) (dockerRuntimeSettings, error) {\n\tif cfg == nil {\n\t\treturn dockerRuntimeSettings{}, errors.New(\"sandbox: docker client requires a config\")\n\t}\n\timage := strings.TrimSpace(cfg.DockerImage)\n\tif image == \"\" {\n\t\treturn dockerRuntimeSettings{}, errors.New(\"sandbox: docker backend requires an image\")\n\t}\n\tsettings := dockerRuntimeSettings{\n\t\tImage:       image,\n\t\tCPULimit:    cfg.DockerCPULimit,\n\t\tMemoryBytes: cfg.DockerMemoryBytes,\n\t\tPidsLimit:   cfg.DockerPidsLimit,\n\t\tNetworkMode: strings.TrimSpace(cfg.DockerNetworkMode),\n\t\tRuntime:     strings.TrimSpace(cfg.DockerRuntime),\n\t\tIdleTTL:     cfg.DockerIdleTTL,\n\t\tHTTPTimeout: cfg.DockerHTTPTimeout,\n\t\tEndpoint: dockerEndpoint{\n\t\t\tHost:         strings.TrimSpace(cfg.DockerHost),\n\t\t\tTLSCertPath:  strings.TrimSpace(cfg.DockerTLSCertPath),\n\t\t\tAllowPrivate: cfg.AllowPrivateEndpoints,","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/docker_remote_client.go#L136-L172","documentation":"dockerSettingsFromConfig projects the workspace Config into Docker runtime settings and refuses to build a Docker remote client when it is handed a nil *Config. The library requires an explicit configuration object because every sandbox backend derives its runtime parameters (image, CPU, memory, pids limits, network policy) from it. A nil config is treated as a programming/caller error rather than something a default can be inferred for.","triggerScenarios":"Calling NewDockerRemoteClient, NewDockerRemoteClientForCheck (or the test helpers newTestDockerClient) with a nil *Config argument, typically because a Config struct was conditionally populated or a nil pointer was passed through from an upstream loader.","commonSituations":"Config loading failed silently earlier and returned nil; a caller short-circuits an optional-config pattern and forwards nil; refactors changed Config from value to pointer semantics and existing call sites now pass nil.","solutions":["Ensure the *Config passed to NewDockerRemoteClient/NewDockerRemoteClientForCheck is non-nil before calling","Check the config-loading function for code paths that can return (nil, nil) and fix them","Fall back to a default Config value when no workspace config is present"],"exampleFix":"// before\nclient, err := sandbox.NewDockerRemoteClient(nil)\n// after\nif cfg == nil {\n    return nil, fmt.Errorf(\"no sandbox config: %w\", err)\n}\nclient, err := sandbox.NewDockerRemoteClient(cfg)","handlingStrategy":"validation","validationCode":"if cfg == nil {\n    return fmt.Errorf(\"docker sandbox requires config: docker client requires a config\")\n}\nif strings.TrimSpace(cfg.DockerImage) == \"\" {\n    return errors.New(\"docker sandbox requires an image\")\n}","typeGuard":"func hasDockerConfig(cfg *sandbox.Config) bool { return cfg != nil }","tryCatchPattern":null,"preventionTips":["Never pass a possibly-nil *Config straight into backend constructors — load and check first","Make config loaders return (Config, error) instead of (nil, nil)","Add a unit test asserting constructors fail fast on nil config"],"tags":["go","sandbox","docker","config","nil-pointer"],"backgroundTag":"missing-configuration","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}