{"record":{"id":"c6ea9a595a5d2424","repo":"siyuan-note/siyuan","slug":"formatrepoerrormsg-err","errorCode":null,"errorMessage":"formatRepoErrorMsg(err)","messagePattern":"formatRepoErrorMsg\\(err\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/sync.go","lineNumber":774,"sourceCode":"\t\treturn\n\t}\n\n\tname = util.RemoveInvalid(name)\n\tif !cloud.IsValidCloudDirName(name) {\n\t\treturn errors.New(Conf.Language(37))\n\t}\n\n\thandleCloudError := cloudRepoErrorHandler()\n\tdefer func() { handleCloudError(err) }()\n\trepo, err := newCloudRepositoryWithAssetSourceLocked()\n\tif err != nil {\n\t\treturn\n\t}\n\n\terr = repo.CreateCloudRepo(name)\n\tif err != nil {\n\t\thandleCloudError(err)\n\t\terr = errors.New(formatRepoErrorMsg(err))\n\t\treturn\n\t}\n\treturn\n}\n\nfunc RemoveCloudSyncDir(name string) (err error) {\n\trelease := lockAssetSourceChange()\n\tdefer release()\n\tif name == Conf.Sync.CloudName {\n\t\tif err = requireCompleteAssetDownloads(); err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\tswitch Conf.Sync.Provider {\n\tcase conf.ProviderSiYuan, conf.ProviderLocal:\n\t\tbreak\n\tdefault:\n\t\terr = errors.New(Conf.Language(131))","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/sync.go#L756-L792","documentation":"CreateCloudSyncDir wraps a failure from repo.CreateCloudRepo(name) with formatRepoErrorMsg, which maps known repository errors (cloud auth failed, cloud object not found, cloud lock contention, decrypt failure, DNS/timeout, etc.) to localized user-facing messages before returning them. The error means the SiYuan cloud repository could not be created; the wrapped message identifies the underlying cause (authentication, network, quota/lock, or file-system problem). The kernel also runs cloudRepoErrorHandler, so the failure is additionally reported through the UI notification path.","triggerScenarios":"Calling CreateCloudSyncDir (HTTP API /api/sync/createCloudSyncDirContract) when: the cloud account token is expired or invalid (ErrCloudAuthFailed); the target repo name already exists remotely (ErrCloudObjectNotFound / conflict); network/DNS to siyuan cloud is down; the cloud data is locked by another device; or the local/remote repo state is corrupt (ErrRepoFatal). Also when Sync.Provider is not SiYuan/Local the earlier Language(131) error fires instead, so this wrapper only triggers for supported providers.","commonSituations":"User logged out or subscription expired so the token is stale; creating a sync dir from a machine with broken DNS or behind a firewall/proxy; another device holds the cloud lock mid-sync; system clock drift triggering ErrSystemTimeIncorrect; running an outdated kernel version rejected as ErrDeprecatedVersion; duplicate repo name from retrying creation.","solutions":["Read the localized message: if it indicates login failure, re-authenticate (Settings - Account - log in again) and retry CreateCloudSyncDir.","If it indicates the repo/object exists, choose a different cloud sync dir name or remove the existing one first via RemoveCloudSyncDir.","If it is a network/DNS/timeout message, fix connectivity (DNS, proxy, firewall) and retry.","If it indicates cloud lock, wait for the other device's sync to finish, then retry.","If it indicates an unsupported/deprecated kernel version, upgrade SiYuan to the latest version.","Check kernel logs for the 'unclassified repository error' line to identify the raw underlying error when no known family matched."],"exampleFix":"// before: caller sees a generic cloud failure and retries blindly\nerr := model.CreateCloudSyncDir(\"main\")\nif err != nil { log.Println(err); return }\n\n// after: authenticate and validate provider/name first, then handle mapped errors\nif conf.ProviderSiYuan != model.Conf.Sync.Provider && conf.ProviderLocal != model.Conf.Sync.Provider {\n    return errors.New(\"cloud sync requires the SiYuan or Local provider\")\n}\nif !model.IsLoggedIn() { // refresh token first\n    return errors.New(\"log in to SiYuan cloud before creating a sync dir\")\n}\nif err := model.CreateCloudSyncDir(name); err != nil {\n    util.PushErrMsg(err.Error(), 7000) // show mapped localized message to user\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// caller-side pre-check (frontend/JS)\nconst cfg = (await fetchPost(\"/api/sync/getSyncInfo\", {})).data;\nif (cfg.provider !== 2 && cfg.provider !== 4) throw new Error(\"provider must be SiYuan or Local\");\nif (!cfg.cloudUser) throw new Error(\"log in to SiYuan cloud first\");\nif (!/^[\\w\\u4e00-\\u9fa5-]+$/.test(name)) throw new Error(\"invalid cloud dir name\");","typeGuard":null,"tryCatchPattern":"try {\n  await fetchPost(\"/api/sync/createCloudSyncDir\", {name});\n} catch (e) {\n  // message is already localized by formatRepoErrorMsg\n  if (/login|auth/i.test(e.message)) openLoginDialog();\n  else if (/exist|already/i.test(e.message)) suggestAlternativeName();\n  else showMessage(e.message);\n}","preventionTips":["Ensure the user is logged in to SiYuan cloud and the subscription is active before creating sync dirs","Validate the dir name with the same rules the kernel uses (util.RemoveInvalid + IsValidCloudDirName)","Keep the system clock synced to avoid time-based auth failures","Check connectivity/DNS before cloud operations in automated scripts"],"tags":["go","cloud-sync","repository","network","authentication"],"backgroundTag":"api-error-response","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"}