usememos/memos · warning

PAT not found

Error message

PAT not found

What it means

The SQLite user_setting driver mirrors the MySQL implementation: load the user's PAT list setting, scan Tokens for TokenHash equality, and return "PAT not found" when the loop completes without a match. It is an expected lookup miss, not a database failure.

Source

Thrown at store/db/sqlite/user_setting.go:124

	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 against the current database
  2. Verify MEMOS_DATA / DSN points at the SQLite file the token was created in
  3. Handle this error as 401 in callers so clients can re-authenticate

Example fix

// before (server middleware)
user, err := store.FindPAT(ctx, userID, hash)
// after
user, err := store.FindPAT(ctx, userID, hash)
if err != nil { // includes "PAT not found"
    return echo.NewHTTPError(http.StatusUnauthorized, "invalid access token")
}
Defensive patterns

Strategy: try-catch

Try / catch

res, err := d.FindPAT(ctx, userID, tokenHash)
if err != nil && strings.Contains(err.Error(), "PAT not found") {
    return nil, echo.NewHTTPError(http.StatusUnauthorized, "invalid access token")
}

Prevention

When it happens

Trigger: Valid-format PAT whose hash is not stored for the user — revoked, deleted, or created on a different database file.

Common situations: Pointing the instance at a new SQLite file path (fresh DB loses all PATs); deleting a token in the UI while automation still uses it; copying an SQLite DB between environments and using tokens minted elsewhere.

Related errors


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