{"record":{"id":"1feabdb05eea2a08","repo":"gastownhall/beads","slug":"resolving-managed-sql-server-config-path-w","errorCode":null,"errorMessage":"resolving managed sql-server config path: %w","messagePattern":"resolving managed sql-server config path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/doltserver/doltserver.go","lineNumber":1405,"sourceCode":"\t\t\t}\n\n\t\t\tvar cmdArgs []string\n\t\t\tif useArchiveLevelConfig {\n\t\t\t\tcfgBody, cfgErr := buildDoltServerYAMLConfig(cfg.Host, actualPort, debug, cfgDir)\n\t\t\t\tif cfgErr != nil {\n\t\t\t\t\tlastErr = fmt.Errorf(\"rendering managed sql-server config: %w\", cfgErr)\n\t\t\t\t\tif !explicitPort {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\t// filepath.Abs defensively: the child's cwd is doltDir (cmd.Dir\n\t\t\t\t// below), so a relative configPath would resolve against the\n\t\t\t\t// wrong directory (matches the sibling dbproxy/server path,\n\t\t\t\t// which abs's its configPath in NewDoltServer).\n\t\t\t\tabsConfigPath, absErr := filepath.Abs(doltServerConfigPath(beadsDir))\n\t\t\t\tif absErr != nil {\n\t\t\t\t\tlastErr = fmt.Errorf(\"resolving managed sql-server config path: %w\", absErr)\n\t\t\t\t\tif !explicitPort {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif werr := os.WriteFile(absConfigPath, cfgBody, 0600); werr != nil {\n\t\t\t\t\tlastErr = fmt.Errorf(\"writing managed sql-server config: %w\", werr)\n\t\t\t\t\tif !explicitPort {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcmdArgs = buildDoltServerArgsWithConfig(absConfigPath, debug, profDir)\n\t\t\t} else {\n\t\t\t\tcmdArgs = buildDoltServerArgs(cfg.Host, actualPort, debug, profDir)\n\t\t\t}\n\n\t\t\tcmd := exec.Command(doltBin, cmdArgs...) //nolint:gosec // doltBin is resolved from PATH, not user input","sourceCodeStart":1387,"sourceCodeEnd":1423,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/doltserver/doltserver.go#L1387-L1423","documentation":"After rendering the config body, Start() converts the managed config file path (doltServerConfigPath(beadsDir)) to an absolute path with filepath.Abs, because the child process's cwd is doltDir and a relative path would resolve against the wrong directory. A filepath.Abs failure (current working directory unresolvable, e.g. deleted cwd) is wrapped as 'resolving managed sql-server config path'.","triggerScenarios":"useArchiveLevelConfig true and filepath.Abs fails — practically only when the process's working directory has been removed or its chain cannot be evaluated.","commonSituations":"The bd process was started from a directory that was later deleted; containers or daemons launched with a nonexistent cwd.","solutions":["Restart bd from an existing working directory (cd / && bd ...).","If bd runs as a daemon, set its WorkingDirectory in the service unit to an existing path.","Ensure nothing deletes the directory bd was launched from while it runs.","Upgrade beads if a released fix caches the absolute path earlier in startup."],"exampleFix":"// before: launched from a dir deleted later\nrm -rf /tmp/scratch   # bd cwd was /tmp/scratch\n// after\ncd / && bd start","handlingStrategy":"try-catch","validationCode":"// ensure the process cwd exists before starting\nclass ExistsSyncGuard { static ok(p){ return require('fs').existsSync(p); } }\nif (!ExistsSyncGuard.ok(process.cwd())) throw new Error('cwd deleted; restart bd from an existing directory');","typeGuard":"function cwdExists() { try { process.cwd(); return true; } catch { return false; } }","tryCatchPattern":"try {\n  await bdStart();\n} catch (e) {\n  if (/resolving managed sql-server config path/.test(e.message)) {\n    // restart bd from an existing working directory\n  }\n  throw e;\n}","preventionTips":["Launch daemons with a WorkingDirectory that always exists.","Don't delete directories a running bd was started from.","Start bd from a stable path such as $HOME or /."],"tags":["filesystem","config","startup"],"backgroundTag":"unresolvable-working-directory","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}