siyuan-note/siyuan · error

invalid user

Error message

invalid user

What it means

errInvalidUser is the sentinel error ('invalid user') returned by getUser when the cloud /apis/siyuan/user endpoint rejects the supplied token (the response indicates the token maps to no valid user). It is matched with errors.Is via IsInvalidUserRefresh and drives resolveCloudUserRefresh: when the refresh fails with this sentinel, the previous account is marked invalid (invalidUserName set, user cleared) instead of being kept.

Solutions

  1. Log in again to obtain a fresh token — refresh marks the old account invalid by design
  2. Confirm the cloud server endpoint matches the account's server
  3. Check system time if the token was issued recently
  4. In code, detect this case with model.IsInvalidUserRefresh(err) and trigger the re-login flow rather than retrying with the same token

Example fix

// before
user, invalidName, invalid := model.ResolveCloudUserRefresh(prev, refreshed, refreshErr)
_ = user // may be nil when invalid
// after
user, invalidName, invalid := model.ResolveCloudUserRefresh(prev, refreshed, refreshErr)
if invalid {
    logging.LogWarnf("account %s invalid, re-login required", invalidName)
    promptRelogin(invalidName)
}
Defensive patterns

Strategy: type-guard

Validate before calling

if token == "" { return errors.New("no token to refresh") }

Type guard

func isInvalidUser(err error) bool { return model.IsInvalidUserRefresh(err) }

Try / catch

refreshed, err := refreshUser(token)
if model.IsInvalidUserRefresh(err) {
    clearCachedAccount(); promptRelogin(); return
}

Prevention

When it happens

Trigger: Token refresh at kernel boot calls getUser(token); the cloud server responds that the token is invalid (expired, revoked, wrong server) and the sentinel is propagated to resolveCloudUserRefresh.

Common situations: Stale token after long inactivity or password change; switching util.GetCloudServer to a region where the account does not exist; corrupted token in config; tests deliberately passing bad tokens (TestResolveCloudUserRefresh).

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/2389c85385f40bff. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/cloud_service.go:699

		desc = audioRegexp.ReplaceAllString(desc, " 语音 ")
		desc = videoRegexp.ReplaceAllString(desc, " 视频 ")
		desc = fileRegexp.ReplaceAllString(desc, " 文件 ")
		desc = strings.ReplaceAll(desc, "\n\n", "")
		desc = strings.TrimSpace(desc)
		shorthand["shorthandDesc"] = desc

		md := shorthand["shorthandContent"].(string)
		shorthand["shorthandMd"] = md
		tree := parse.Parse("", []byte(md), luteEngine.ParseOptions)
		luteEngine.RenderOptions.ProtyleMarkNetImg = false
		content := luteEngine.ProtylePreview(tree, luteEngine.RenderOptions, luteEngine.ParseOptions)
		shorthand["shorthandContent"] = content
	}
	return
}

var (
	errInvalidUser       = errors.New("invalid user")
	errRequestUserFailed = errors.New("request user failed")
)

func getUser(token string) (*conf.User, error) {
	result := map[string]any{}
	request := httpclient.NewCloudRequest30s().SetRetryCount(0)
	resp, err := request.
		SetSuccessResult(&result).
		SetBody(map[string]string{"token": token}).
		Post(util.GetCloudServer() + "/apis/siyuan/user")
	if err != nil {
		logging.LogErrorf("get community user failed: %s", err)
		return nil, errRequestUserFailed
	}
	if http.StatusOK != resp.StatusCode {
		logging.LogErrorf("get community user failed: %d", resp.StatusCode)
		if http.StatusUnauthorized == resp.StatusCode {
			return nil, errInvalidUser

View on GitHub (pinned to 9f775e8a12)