{"record":{"id":"f149f5abf91a0d8f","repo":"charmbracelet/crush","slug":"cannot-convert-cwd-to-absolute-path-w","errorCode":null,"errorMessage":"cannot convert CWD to absolute path: %w","messagePattern":"cannot convert CWD to absolute path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/fsext/lookup.go","lineNumber":166,"sourceCode":"\t\t\tfound = append(found, fpath)\n\t\t}\n\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn found, nil\n}\n\n// traverseUp walks up from given directory up until filesystem root reached.\n// It passes absolute path of current directory and staring directory owner ID\n// to callback function. It is up to user to check ownership.\nfunc traverseUp(dir string, walkFn func(dir string, owner int) error) error {\n\tcwd, err := filepath.Abs(dir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot convert CWD to absolute path: %w\", err)\n\t}\n\n\towner, err := Owner(dir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot get ownership: %w\", err)\n\t}\n\n\tfor {\n\t\terr := walkFn(cwd, owner)\n\t\tif err == nil || errors.Is(err, filepath.SkipDir) {\n\t\t\tparent := filepath.Dir(cwd)\n\t\t\tif parent == cwd {\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\tcwd = parent\n\t\t\tcontinue\n\t\t}","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/fsext/lookup.go#L148-L184","documentation":"traverseUp (used by Lookup and LookupClosest) converts the starting directory to an absolute path with filepath.Abs before walking. This error is returned when filepath.Abs fails, which happens only when os.Getwd fails while resolving a relative dir.","triggerScenarios":"Passing a relative path (including \"\" or \".\") to Lookup/LookupClosest while the process working directory is unreadable — e.g. the CWD directory was deleted, lacks execute permission, or is on a failed mount.","commonSituations":"Running the tool from a directory that was removed by another process (common after builds clean the tree); dropping into a directory without +x for the current user; containers with a deleted working directory.","solutions":["Pass an absolute path to Lookup instead of a relative one so filepath.Abs never needs os.Getwd","Restore or recreate the process working directory, or chdir to a valid directory first","Fix permissions on the current directory (chmod +x) or remount a failed filesystem","Restart the process from a valid directory"],"exampleFix":"// before\nfound, err := fsext.Lookup(\".\", \".git\")\n// after\nabsDir, err := filepath.Abs(\"/project/root\") // absolute input avoids Getwd\nif err != nil {\n    return err\n}\nfound, err := fsext.Lookup(absDir, \".git\")","handlingStrategy":"validation","validationCode":"abs, err := filepath.Abs(dir) // fails only via Getwd for relative dir\nif err != nil {\n    return fmt.Errorf(\"starting dir not resolvable: %w\", err)\n}\nif _, err := os.Stat(abs); err != nil {\n    return fmt.Errorf(\"starting dir unavailable: %w\", err)\n}","typeGuard":"func dirIsResolvable(dir string) bool {\n    abs, err := filepath.Abs(dir)\n    return err == nil && func() bool { _, err := os.Stat(abs); return err == nil }()\n}","tryCatchPattern":"found, err := fsext.Lookup(dir, targets...)\nif err != nil {\n    if strings.Contains(err.Error(), \"cannot convert CWD to absolute path\") {\n        // fall back to absolute input path\n        if abs, aerr := filepath.Abs(dir); aerr == nil {\n            found, err = fsext.Lookup(abs, targets...)\n        }\n    }\n    if err != nil {\n        return err\n    }\n}","preventionTips":["Always pass absolute paths to Lookup/LookupClosest","Don't leave the process CWD pointing at deleted directories","Ensure the runtime user has +x on all CWD ancestors","On Linux, note os.Getwd can fail without $PWD set correctly; rely on absolute inputs"],"tags":["filesystem","path-resolution","cwd"],"backgroundTag":"cwd-resolution-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}