{"record":{"id":"82900d743e1a307e","repo":"gastownhall/beads","slug":"applying-s-w","errorCode":null,"errorMessage":"applying %s: %w","messagePattern":"applying (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":3285,"sourceCode":"\t\t\t}\n\t\t\t_ = os.Unsetenv(key)\n\t\t}\n\t}\n\n\tfor _, mut := range muts {\n\t\tif _, seen := saved[mut.key]; !seen {\n\t\t\tvalue, present := os.LookupEnv(mut.key)\n\t\t\tsaved[mut.key] = savedEnv{value: value, present: present}\n\t\t}\n\t\tvar applyErr error\n\t\tif mut.unset {\n\t\t\tapplyErr = os.Unsetenv(mut.key)\n\t\t} else {\n\t\t\tapplyErr = os.Setenv(mut.key, mut.value)\n\t\t}\n\t\tif applyErr != nil {\n\t\t\trestore()\n\t\t\treturn noop, fmt.Errorf(\"applying %s: %w\", mut.key, applyErr)\n\t\t}\n\t}\n\treturn restore, nil\n}\n\nfunc initDoltServerTLSFromEnv() bool {\n\treturn (&configfile.Config{}).GetDoltServerTLS()\n}\n\nfunc initTimeCloneConfig(serverMode bool, serverHost string, serverPort int, serverSocket, serverUser, dbName string) *configfile.Config {\n\tcfg := configfile.DefaultConfig()\n\tcfg.Backend = configfile.BackendDolt\n\tcfg.DoltDatabase = dbName\n\tif serverMode {\n\t\tcfg.DoltMode = configfile.DoltModeServer\n\t\tcfg.DoltServerHost = configfile.DefaultDoltServerHost\n\t\tcfg.DoltServerUser = configfile.DefaultDoltServerUser\n\t} else {","sourceCodeStart":3267,"sourceCodeEnd":3303,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L3267-L3303","documentation":"promoteExplicitServerConnFlags applies the validated env mutations (BEADS_DOLT_SERVER_HOST/PORT/USER/...) via os.Setenv/os.Unsetenv. If the OS-level env write fails, the already-applied mutations are rolled back via restore() and this error wraps the key and underlying cause. In practice os.Setenv rarely fails, so this usually indicates an out-of-memory or extreme environment-block condition.","triggerScenarios":"Applying a validated serverConnEnvMutation where os.Setenv or os.Unsetenv returns an error, aborting flag promotion and restoring prior env state.","commonSituations":"Memory exhaustion during process setup; very large environment blocks near OS limits; exotic sandboxing runtimes that intercept or forbid env changes.","solutions":["Retry the command after checking system memory and environment size","Reduce the environment block size (unset unneeded variables)","Simplify the invocation (pass fewer promoted flags) to reduce mutation count","If using a sandbox wrapper, verify it permits os.Setenv for the bd process"],"exampleFix":"// before: near-OS-limit environment\n$ env $(huge-env) bd init --server-host h\napplying BEADS_DOLT_SERVER_HOST: setenv: cannot allocate memory\n// after\n$ env -i PATH=$PATH HOME=$HOME bd init --server-host h","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"restore, err := promoteExplicitServerConnFlags(cmd); if err != nil { defer restore(); return fmt.Errorf(\"flag promotion: %w\", err) }","preventionTips":["Keep the process environment block reasonably sized","Retry once on transient setenv allocation failures","Avoid exotic sandbox wrappers around bd when promoting flags","Monitor system memory in constrained environments"],"tags":["environment","dolt-server","flags","os"],"backgroundTag":"setenv-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}