{"record":{"id":"1530832ff20c8bcc","repo":"gastownhall/beads","slug":"writing-managed-sql-server-config-w","errorCode":null,"errorMessage":"writing managed sql-server config: %w","messagePattern":"writing managed sql-server config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/doltserver/doltserver.go","lineNumber":1412,"sourceCode":"\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\n\t\t\tcmd.Dir = doltDir\n\t\t\tcmd.Stdout = logFile\n\t\t\tcmd.Stderr = logFile\n\t\t\tcmd.Stdin = nil\n\t\t\tcmd.SysProcAttr = procAttrDetached()\n\t\t\tcmd.Env = ServerSpawnEnv()\n","sourceCodeStart":1394,"sourceCodeEnd":1430,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/doltserver/doltserver.go#L1394-L1430","documentation":"Start() writes the rendered YAML to the managed config file (mode 0600) so the child dolt sql-server can load it via -config. An os.WriteFile failure is wrapped as 'writing managed sql-server config'. Non-explicit ports retry; explicit ports stop and surface lastErr.","triggerScenarios":"os.WriteFile(absConfigPath, cfgBody, 0600) fails: parent directory missing/unwritable, disk full, or path points at a directory.","commonSituations":"Read-only filesystem after mount remount; quota exceeded; beads dir recreated by another process mid-start; permission drift after running bd as different users.","solutions":["Check the beads dir is writable by the current user (ls -ld; chown/chmod if needed).","Remove any directory/file collision at the config path (a directory named like the config file).","Free disk space / check quota (df -h, quota).","Confirm no external process (backup/sync tool) is deleting or replacing the beads dir during startup."],"exampleFix":"// before\nls -ld ~/.beads   # dr-xr-xr-x, read-only\n// after\nchmod u+w ~/.beads && bd start","handlingStrategy":"validation","validationCode":"const cfgPath = path.join(dataDir, 'dolt-server.yaml');\nconst st = await fs.stat(dataDir).catch(() => null);\nif (!st || !st.isDirectory()) throw new Error('beads dir missing');\nawait fs.access(dataDir, fs.constants.W_OK);\nawait fs.access(path.dirname(cfgPath), fs.constants.W_OK);","typeGuard":"null","tryCatchPattern":"try {\n  await bdStart();\n} catch (e) {\n  if (/writing managed sql-server config/.test(e.message)) {\n    // chown/chmod the beads dir, check disk space, then retry\n  }\n  throw e;\n}","preventionTips":["Keep the beads dir writable for the service user.","Watch disk quotas and free space.","Exclude the beads dir from tools that flip it read-only.","Recreate dir permissions after user/uid changes."],"tags":["filesystem","config","startup"],"backgroundTag":"config-file-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}