{"record":{"id":"2389c85385f40bff","repo":"siyuan-note/siyuan","slug":"invalid-user","errorCode":null,"errorMessage":"invalid user","messagePattern":"invalid user","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/cloud_service.go","lineNumber":699,"sourceCode":"\t\tdesc = audioRegexp.ReplaceAllString(desc, \" 语音 \")\n\t\tdesc = videoRegexp.ReplaceAllString(desc, \" 视频 \")\n\t\tdesc = fileRegexp.ReplaceAllString(desc, \" 文件 \")\n\t\tdesc = strings.ReplaceAll(desc, \"\\n\\n\", \"\")\n\t\tdesc = strings.TrimSpace(desc)\n\t\tshorthand[\"shorthandDesc\"] = desc\n\n\t\tmd := shorthand[\"shorthandContent\"].(string)\n\t\tshorthand[\"shorthandMd\"] = md\n\t\ttree := parse.Parse(\"\", []byte(md), luteEngine.ParseOptions)\n\t\tluteEngine.RenderOptions.ProtyleMarkNetImg = false\n\t\tcontent := luteEngine.ProtylePreview(tree, luteEngine.RenderOptions, luteEngine.ParseOptions)\n\t\tshorthand[\"shorthandContent\"] = content\n\t}\n\treturn\n}\n\nvar (\n\terrInvalidUser       = errors.New(\"invalid user\")\n\terrRequestUserFailed = errors.New(\"request user failed\")\n)\n\nfunc getUser(token string) (*conf.User, error) {\n\tresult := map[string]any{}\n\trequest := httpclient.NewCloudRequest30s().SetRetryCount(0)\n\tresp, err := request.\n\t\tSetSuccessResult(&result).\n\t\tSetBody(map[string]string{\"token\": token}).\n\t\tPost(util.GetCloudServer() + \"/apis/siyuan/user\")\n\tif err != nil {\n\t\tlogging.LogErrorf(\"get community user failed: %s\", err)\n\t\treturn nil, errRequestUserFailed\n\t}\n\tif http.StatusOK != resp.StatusCode {\n\t\tlogging.LogErrorf(\"get community user failed: %d\", resp.StatusCode)\n\t\tif http.StatusUnauthorized == resp.StatusCode {\n\t\t\treturn nil, errInvalidUser","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/cloud_service.go#L681-L717","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Log in again to obtain a fresh token — refresh marks the old account invalid by design","Confirm the cloud server endpoint matches the account's server","Check system time if the token was issued recently","In code, detect this case with model.IsInvalidUserRefresh(err) and trigger the re-login flow rather than retrying with the same token"],"exampleFix":"// before\nuser, invalidName, invalid := model.ResolveCloudUserRefresh(prev, refreshed, refreshErr)\n_ = user // may be nil when invalid\n// after\nuser, invalidName, invalid := model.ResolveCloudUserRefresh(prev, refreshed, refreshErr)\nif invalid {\n    logging.LogWarnf(\"account %s invalid, re-login required\", invalidName)\n    promptRelogin(invalidName)\n}","handlingStrategy":"type-guard","validationCode":"if token == \"\" { return errors.New(\"no token to refresh\") }","typeGuard":"func isInvalidUser(err error) bool { return model.IsInvalidUserRefresh(err) }","tryCatchPattern":"refreshed, err := refreshUser(token)\nif model.IsInvalidUserRefresh(err) {\n    clearCachedAccount(); promptRelogin(); return\n}","preventionTips":["Use errors.Is(err, model.IsInvalidUserRefresh) semantics — never string-compare 'invalid user'","Re-login promptly after refresh reports an invalid account; do not reuse the old token","Verify the cloud server endpoint before assuming the token is bad"],"tags":["authentication","sentinel-error","token-expired","cloud"],"backgroundTag":"jwt-token-expired","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}