{"record":{"id":"c7b7fadce8a9451b","repo":"kovidgoyal/kitty","slug":"could-not-find-the-current-uid-d-in-the-dscl-use","errorCode":null,"errorMessage":"Could not find the current uid: %d in the DSCL user database","messagePattern":"Could not find the current uid: (.+?) in the DSCL user database","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/utils/passwd.go","lineNumber":160,"sourceCode":"\t}\n\treturn ans, fmt.Errorf(\"No user record available for user with UID: %#v\", u.Uid)\n}\n\nfunc CurrentUser() (ans *user.User, err error) {\n\tans, err = user.Current()\n\tif err != nil && runtime.GOOS == \"darwin\" {\n\t\tuid := strconv.Itoa(os.Geteuid())\n\t\tdb := dscl_user_database()\n\t\tif dscl_error != nil {\n\t\t\terr = dscl_error\n\t\t\treturn\n\t\t}\n\t\tif rec, found := db[uid]; found {\n\t\t\tu := user.User{Uid: uid, Gid: rec.Gid, Username: rec.Username, Name: rec.Gecos, HomeDir: rec.Home}\n\t\t\tans = &u\n\t\t\terr = nil\n\t\t} else {\n\t\t\terr = fmt.Errorf(\"Could not find the current uid: %d in the DSCL user database\", os.Geteuid())\n\t\t}\n\t}\n\treturn\n}\n\nfunc LoginShellForCurrentUser() (ans string, err error) {\n\tu, err := CurrentUser()\n\tif err != nil {\n\t\treturn ans, err\n\t}\n\treturn LoginShellForUser(u)\n}\n","sourceCodeStart":142,"sourceCodeEnd":173,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/utils/passwd.go#L142-L173","documentation":"CurrentUser wraps user.Current(); on macOS when the stdlib lookup fails it falls back to querying the DSCL (Directory Services) database by effective UID. This error means the DSCL fallback also found no record for the current euid, so the current user could not be identified at all.","triggerScenarios":"Running under an euid with no DSCL record: leaked euid from setuid helper, ssh session with a deleted account, sandboxed/launchd context where Directory Services is unreachable or the record is missing.","commonSituations":"macOS-specific: user account removed while processes persist, privilege drops to nobody-like UIDs, or DS corruption. Callers like LoginShellForCurrentUser and tests then fail.","solutions":["Verify identity: `id` and `dscl . -search /Users UniqueID $(id -u)`.","If the account was deleted, recreate it or restart the session/process under a valid user.","For daemons, set the user explicitly instead of relying on euid discovery.","As a last resort, set USER/LOGNAME env vars and construct a user.User manually."],"exampleFix":"// before\nu, err := utils.CurrentUser()\n// after\nu, err := utils.CurrentUser()\nif err != nil {\n    u = &user.User{Uid: strconv.Itoa(os.Geteuid()), Username: os.Getenv(\"USER\")}\n}","handlingStrategy":"fallback","validationCode":"if _, err := user.Current(); err != nil && runtime.GOOS == \"darwin\" {\n    if _, derr := exec.LookPath(\"dscl\"); derr != nil {\n        // DSCL fallback will also fail; supply env-based identity\n    }\n}","typeGuard":null,"tryCatchPattern":"u, err := utils.CurrentUser()\nif err != nil {\n    u = &user.User{Uid: strconv.Itoa(os.Geteuid()), Username: os.Getenv(\"USER\")}\n    if u.Username == \"\" { u.Username = \"unknown\" }\n}","preventionTips":["Set USER/LOGNAME in daemon environments.","Avoid running under UIDs with no account record.","On macOS, validate with dscl . -search /Users UniqueID $(id -u)."],"tags":["go","macos","dscl","user-identity"],"backgroundTag":"user-lookup-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}