{"record":{"id":"08552e9322cd05a9","repo":"siyuan-note/siyuan","slug":"request-user-failed","errorCode":null,"errorMessage":"request user failed","messagePattern":"request user failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/cloud_service.go","lineNumber":700,"sourceCode":"\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\n\t\t}","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/cloud_service.go#L682-L718","documentation":"\"request user failed\" (errRequestUserFailed) is returned by the SiYuan kernel's cloud-account layer when the logged-in user cannot be resolved consistently. It is thrown when the user's token expiry time cannot be parsed during a cloud user refresh, or when the configured user changed while a refresh was in flight (concurrent account switch detected). It deliberately masks the underlying detail so callers get a stable, well-known sentinel error.","triggerScenarios":"Calling model.RefreshUser(token) or getUser(token) when the cloud API returns a user whose UserTokenExpireTime fails strconv/time parsing (cloud_service.go:421), or when Conf.GetUser() differs from previousUser after acquiring cloudAccountMu (cloud_service.go:441), i.e. another goroutine switched accounts mid-refresh. Also surfaced by TestResolveCloudUserRefresh.","commonSituations":"The SiYuan cloud server changes its token-expiry-time format after an upgrade; multiple concurrent requests refresh the same account while the user logs in/out or switches accounts in another window; a corrupted cached user record in conf produces an unparseable expiry time.","solutions":["Log out and log back in to the SiYuan cloud account (Settings - Account) so the cached user record and token expiry time are rebuilt","Retry the refresh after a moment — if it was a concurrent account-switch race, the second attempt will see a stable user","Upgrade SiYuan to the latest version; older kernels may fail to parse a new expiry-time format returned by the cloud server","If it persists, back up and reset the workspace's account info (conf.json user section) to clear the corrupted user record"],"exampleFix":"// concurrent refresh race in caller code\nuser, err := model.RefreshUser(token)\nif errors.Is(err, model.ErrRequestUserFailed) { // retry once after account lock settles\n    time.Sleep(500 * time.Millisecond)\n    user, err = model.RefreshUser(token)\n}","handlingStrategy":"retry","validationCode":"// ensure a user exists and token parses before refresh\nconst u = window.siyuan?.user;\nif (!u || !u.UserToken) return;\nif (isNaN(Date.parse(u.UserTokenExpireTime))) console.warn(\"token expire time unparseable, refresh may fail\");","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetchSyncPost(\"/api/user/refreshUser\", {token});\n  if (res.code !== 0) throw new Error(res.msg);\n} catch (e) {\n  // errRequestUserFailed: retry once, then prompt re-login\n  await new Promise(r => setTimeout(r, 500));\n  // second attempt, then surface \"please log in again\"\n}","preventionTips":["Avoid concurrent account refreshes; serialize account operations in plugin/UI code","Keep SiYuan and the cloud account session fresh so expiry-time formats stay compatible","Detect this sentinel and fall back to a full re-login flow rather than retrying indefinitely"],"tags":["cloud-account","concurrency","network","go"],"backgroundTag":"api-request-failed","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"}