{"record":{"id":"a0a53d4f60d49217","repo":"dagger/dagger","slug":"parse-dagger-engine-num-cpu-w","errorCode":null,"errorMessage":"parse DAGGER_ENGINE_NUM_CPU: %w","messagePattern":"parse DAGGER_ENGINE_NUM_CPU: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/client/client.go","lineNumber":277,"sourceCode":"\n\t// NB: don't propagate this ctx, we don't want everything tucked beneath connect\n\tconnectCtx, span := Tracer(ctx).Start(ctx, \"connect\", connectSpanOpts...)\n\tdefer telemetry.EndWithCause(span, &rerr)\n\tslog := slog.SpanLogger(connectCtx, InstrumentationLibrary)\n\n\tnestedSessionPortVal, isNestedSession := os.LookupEnv(\"DAGGER_SESSION_PORT\")\n\tif isNestedSession {\n\t\tnestedSessionPort, err := strconv.Atoi(nestedSessionPortVal)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"parse DAGGER_SESSION_PORT: %w\", err)\n\t\t}\n\t\tc.nestedSessionPort = nestedSessionPort\n\t\tc.SecretToken = os.Getenv(\"DAGGER_SESSION_TOKEN\")\n\t\tnumCPUVal := os.Getenv(\"DAGGER_ENGINE_NUM_CPU\")\n\t\tif numCPUVal != \"\" {\n\t\t\tnumCPU, err := strconv.Atoi(numCPUVal)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parse DAGGER_ENGINE_NUM_CPU: %w\", err)\n\t\t\t}\n\t\t\tc.numCPU = numCPU\n\t\t}\n\t\tc.httpClient = c.newHTTPClient()\n\t\tif err := c.init(connectCtx); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"initialize nested client: %w\", err)\n\t\t}\n\t\tif err := c.subscribeTelemetry(connectCtx); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"subscribe to telemetry: %w\", err)\n\t\t}\n\t\tif err := c.daggerConnect(connectCtx); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to connect to dagger: %w\", err)\n\t\t}\n\t\treturn c, nil\n\t}\n\n\t// Check if any of the upstream cache importers/exporters are enabled.\n\t// Note that this is not the cache service support in engine/cache/, that","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/client/client.go#L259-L295","documentation":"Inside a nested Dagger session, the optional DAGGER_ENGINE_NUM_CPU env var is read to configure engine CPU count. If present but not a valid integer, Connect fails with this wrapped strconv error. It only triggers when the variable is non-empty, so the variable exists but holds non-numeric content.","triggerScenarios":"Calling dagger.Connect() in a nested session where DAGGER_ENGINE_NUM_CPU is set to a non-integer string like \"four\", \"4.0\", or \" 4\".","commonSituations":"Users setting CPU limits as floats or with units (\"4cpus\"); Kubernetes-style resource strings pasted into the env; quoting artifacts from shell profiles.","solutions":["Unset DAGGER_ENGINE_NUM_CPU if you don't need to override CPU count: unset DAGGER_ENGINE_NUM_CPU.","Set it to a plain positive integer: export DAGGER_ENGINE_NUM_CPU=4.","Convert float/unit values to integers at the source (e.g. in the engine launcher that exports the variable)."],"exampleFix":"// before\nexport DAGGER_ENGINE_NUM_CPU=4.0\n// after\nexport DAGGER_ENGINE_NUM_CPU=4","handlingStrategy":"validation","validationCode":"if v := os.Getenv(\"DAGGER_ENGINE_NUM_CPU\"); v != \"\" {\n    if n, err := strconv.Atoi(v); err != nil || n <= 0 {\n        return fmt.Errorf(\"invalid DAGGER_ENGINE_NUM_CPU %q\", v)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := dagger.Connect(ctx); err != nil && strings.Contains(err.Error(), \"parse DAGGER_ENGINE_NUM_CPU\") {\n    os.Unsetenv(\"DAGGER_ENGINE_NUM_CPU\")\n    // retry connect\n}","preventionTips":["Only set DAGGER_ENGINE_NUM_CPU to a plain positive integer.","Don't paste k8s resource quantities (\"4\", \"4000m\") into this var.","Unset it in environments where you don't intend to override CPU config."],"tags":["go","env-var","nested-session","parsing"],"backgroundTag":"invalid-env-var-value","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"}