{"record":{"id":"fca891ca28f110e3","repo":"gastownhall/beads","slug":"resolve-absolute-path-w","errorCode":null,"errorMessage":"resolve absolute path: %w","messagePattern":"resolve absolute path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/backup.go","lineNumber":54,"sourceCode":"// same name is overwritten. Mirrors the CLI: dolt backup restore [--force] <url> <db_name>\nfunc BackupRestore(ctx context.Context, db DBConn, url, dbName string, force bool) error {\n\tif force {\n\t\tif _, err := db.ExecContext(ctx, \"CALL DOLT_BACKUP('restore', '--force', ?, ?)\", url, dbName); err != nil {\n\t\t\treturn fmt.Errorf(\"restore from backup %s: %w\", url, err)\n\t\t}\n\t} else {\n\t\tif _, err := db.ExecContext(ctx, \"CALL DOLT_BACKUP('restore', ?, ?)\", url, dbName); err != nil {\n\t\t\treturn fmt.Errorf(\"restore from backup %s: %w\", url, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// DirToFileURL resolves dir to an absolute path and returns a file:// URL.\nfunc DirToFileURL(dir string) (string, error) {\n\tabs, err := filepath.Abs(dir)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"resolve absolute path: %w\", err)\n\t}\n\treturn \"file://\" + abs, nil\n}\n\n// ExtractAddressConflictName parses the conflicting remote name from a Dolt\n// \"address conflict with a remote\" error.\n//\n// Dolt returns errors of the form:\n//\n//\tError 1105: address conflict with a remote: 'name' -> url\n//\n// When BackupAdd fails because another remote (e.g. \"default\", registered by\n// `bd backup init`) already points to the same URL, the caller can use the\n// conflicting name to sync directly rather than treating it as a hard error.\n// Returns \"\" if the error is not an address conflict.\nfunc ExtractAddressConflictName(err error) string {\n\tif err == nil {\n\t\treturn \"\"","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/backup.go#L36-L72","documentation":"DirToFileURL calls filepath.Abs on dir and wraps failure as \"resolve absolute path: <cause>\" before returning a file:// URL. filepath.Abs only errors when Getwd fails (e.g. relative resolution needs the current working directory and it was deleted). This is rare and environmental.","triggerScenarios":"DirToFileURL(dir) when filepath.Abs fails: the process's current working directory has been removed and dir is relative, so Getwd inside filepath.Abs errors.","commonSituations":"Running a long-lived process whose working directory was deleted (tmpdir cleanup); launching from a removed directory; container environments with cleaned cwd.","solutions":["Pass an absolute directory path so filepath.Abs short-circuits without Getwd","Restart the process from an existing working directory","Check os.Getwd() health if the process runs long after directory cleanup"],"exampleFix":"// before\nu, err := vcops.DirToFileURL(\"backups/db\")\n// after\nu, err := vcops.DirToFileURL(\"/var/backups/db\")\nif err != nil { return fmt.Errorf(\"backup url: %w\", err) }","handlingStrategy":"validation","validationCode":"func safeDirToFileURL(dir string) (string, error) {\n\tif filepath.IsAbs(dir) { return \"file://\" + filepath.Clean(dir), nil }\n\treturn vcops.DirToFileURL(dir)\n}","typeGuard":null,"tryCatchPattern":"u, err := vcops.DirToFileURL(dir)\nif err != nil {\n\tif strings.Contains(err.Error(), \"resolve absolute path\") {\n\t\treturn fmt.Errorf(\"cwd unavailable; pass an absolute path: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Prefer absolute paths in configuration","Restart services whose working directory was removed","Pin working directory at startup with os.Chdir to a guaranteed-existing dir"],"tags":["filesystem","path","url"],"backgroundTag":"working-directory-unavailable","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}