kovidgoyal/kitty · error

Could not find the current uid: %d in the DSCL user database

Error message

Could not find the current uid: %d in the DSCL user database

What it means

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.

Source

Thrown at tools/utils/passwd.go:160

	}
	return ans, fmt.Errorf("No user record available for user with UID: %#v", u.Uid)
}

func CurrentUser() (ans *user.User, err error) {
	ans, err = user.Current()
	if err != nil && runtime.GOOS == "darwin" {
		uid := strconv.Itoa(os.Geteuid())
		db := dscl_user_database()
		if dscl_error != nil {
			err = dscl_error
			return
		}
		if rec, found := db[uid]; found {
			u := user.User{Uid: uid, Gid: rec.Gid, Username: rec.Username, Name: rec.Gecos, HomeDir: rec.Home}
			ans = &u
			err = nil
		} else {
			err = fmt.Errorf("Could not find the current uid: %d in the DSCL user database", os.Geteuid())
		}
	}
	return
}

func LoginShellForCurrentUser() (ans string, err error) {
	u, err := CurrentUser()
	if err != nil {
		return ans, err
	}
	return LoginShellForUser(u)
}

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Verify identity: `id` and `dscl . -search /Users UniqueID $(id -u)`.
  2. If the account was deleted, recreate it or restart the session/process under a valid user.
  3. For daemons, set the user explicitly instead of relying on euid discovery.
  4. As a last resort, set USER/LOGNAME env vars and construct a user.User manually.

Example fix

// before
u, err := utils.CurrentUser()
// after
u, err := utils.CurrentUser()
if err != nil {
    u = &user.User{Uid: strconv.Itoa(os.Geteuid()), Username: os.Getenv("USER")}
}
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := user.Current(); err != nil && runtime.GOOS == "darwin" {
    if _, derr := exec.LookPath("dscl"); derr != nil {
        // DSCL fallback will also fail; supply env-based identity
    }
}

Try / catch

u, err := utils.CurrentUser()
if err != nil {
    u = &user.User{Uid: strconv.Itoa(os.Geteuid()), Username: os.Getenv("USER")}
    if u.Username == "" { u.Username = "unknown" }
}

Prevention

When it happens

Trigger: 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.

Common situations: macOS-specific: user account removed while processes persist, privilege drops to nobody-like UIDs, or DS corruption. Callers like LoginShellForCurrentUser and tests then fail.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/c7b7fadce8a9451b. Report an issue: GitHub.