theonedev/onedev · error · ExplicitException

Unknown user does not have git identity

Error message

Unknown user does not have git identity

What it means

User.asPerson() converts a OneDev user into a JGit PersonIdent (git commit author/committer identity). The built-in 'Unknown' user represents unauthenticated/anonymous access and has no real name or email, so it cannot produce a git identity — calling asPerson() on it throws this ExplicitException.

Source

Thrown at server-core/src/main/java/io/onedev/server/model/User.java:776

	public Collection<SsoAccount> getSsoAccounts() {
		return ssoAccounts;
	}

	public void setSsoAccounts(Collection<SsoAccount> ssoAccounts) {
		this.ssoAccounts = ssoAccounts;
	}
	
	@Override
	public String toString() {
		return MoreObjects.toStringHelper(this)
				.add("name", getName())
				.toString();
	}
	
	public PersonIdent asPerson() {
		if (isUnknown()) 
			throw new ExplicitException("Unknown user does not have git identity");
		else if (isSystem())
			return new PersonIdent(User.SYSTEM_NAME, getSystemNoreplyEmailAddress());
		else 
			return new PersonIdent(getDisplayName(), getGitEmailAddress().getValue());		
	}
	
	public String getDisplayName() {
		if (getFullName() != null)
			return getFullName();
		else
			return getName();
	}
	
	public boolean isRoot() {
		return ROOT_ID.equals(getId());
	}

	public boolean isSystem() {

View on GitHub (pinned to d44925c47c)

Solutions

  1. Ensure the operation runs with an authenticated user; resolve the actual User before calling asPerson()
  2. Guard the call with if (!user.isUnknown()) and handle anonymous users explicitly (skip attribution or use a service account)
  3. Use the system user (User.system) instead when an operation must be attributed but has no human actor

Example fix

// before
PersonIdent ident = user.asPerson();
// after
if (user.isUnknown()) {
    throw new IllegalStateException("Cannot attribute git operation to unknown user");
}
PersonIdent ident = user.asPerson();
Defensive patterns

Strategy: type-guard

Validate before calling

if (user == null || user.isUnknown()) throw new IllegalArgumentException("authenticated user required");

Type guard

boolean hasGitIdentity(User u) { return u != null && !u.isUnknown(); }

Try / catch

try {
    PersonIdent ident = user.asPerson();
} catch (ExplicitException e) {
    ident = new PersonIdent(User.SYSTEM_NAME, "system@example.com");
}

Prevention

When it happens

Trigger: Calling user.asPerson() when user.isUnknown() is true — e.g. attempting to record a commit/push attribution for an anonymous or unresolved user identity.

Common situations: Code paths that attribute git operations before authentication is resolved; push hooks or scripts operating on the Unknown user; testing code that instantiates the unknown user and formats an identity.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/a6fdaae8a166fec4. Report an issue: GitHub.