usememos/memos · warning

PAT not found

Error message

PAT not found

What it means

The MySQL user_setting driver reads the USER_SETTING row holding the PAT list, unmarshals it, and scans tokens for a matching TokenHash. "PAT not found" means the hash simply is not in the stored list — either the token was revoked, belongs to another user, or the hash input differs (PATs are matched by hash, never plaintext).

Source

Thrown at store/db/mysql/user_setting.go:108

	if err != nil {
		return nil, err
	}

	patsUserSetting := &storepb.PersonalAccessTokensUserSetting{}
	if err := protojsonUnmarshaler.Unmarshal([]byte(tokensJSON), patsUserSetting); err != nil {
		return nil, err
	}

	for _, pat := range patsUserSetting.Tokens {
		if pat.TokenHash == tokenHash {
			return &store.PATQueryResult{
				UserID: userID,
				PAT:    pat,
			}, nil
		}
	}

	return nil, errors.New("PAT not found")
}

View on GitHub (pinned to 14d757ce1f)

Solutions

  1. Regenerate the PAT in Settings > Access Tokens and update the client
  2. Confirm the token is passed intact (no truncation by shells or editors)
  3. Map this error to gRPC codes.NotFound / HTTP 401 at the API layer so clients refresh credentials

Example fix

// before
result, err := mysqlStore.FindPAT(ctx, userID, tokenHash) // used raw token
// after
result, err := mysqlStore.FindPAT(ctx, userID, hashToken(rawToken))
Defensive patterns

Strategy: try-catch

Try / catch

res, err := d.FindPAT(ctx, userID, tokenHash)
if err != nil {
    if strings.Contains(err.Error(), "PAT not found") {
        return nil, status.Error(codes.Unauthenticated, "invalid personal access token")
    }
    return nil, status.Error(codes.Internal, "failed to query PAT")
}

Prevention

When it happens

Trigger: Authenticating with a PAT whose hash does not match any stored token for that user ID; using a revoked or rotated PAT; passing the raw token where a hash is expected.

Common situations: Expired/revoked tokens still configured in scripts; tokens created before a hashing-scheme change; multi-user instances where the userID lookup and token belong to different accounts.

Related errors


AI-assisted analysis of usememos/memos@14d757ce1f (2026-08-15). Data as JSON: /api/errors/22c59ebbdf6af5bc. Report an issue: GitHub.