{"record":{"id":"8e51d78c0cf1d6cc","repo":"siyuan-note/siyuan","slug":"the-synchronization-function-can-only-be-activated-after","errorCode":null,"errorMessage":"The synchronization function can only be activated after adding/selecting the cloud synchronization directory","messagePattern":"The synchronization function can only be activated after adding/selecting the cloud synchronization directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/sync.go","lineNumber":237,"sourceCode":"\tif 1 == code {\n\t\t// 启动同步成功后消费本地速记临时文件，避免移动端开启云同步时需手动触发同步才能刷新闪念速记\n\t\tconsumeShorthands()\n\t}\n\treturn\n}\n\nfunc SyncData(byHand bool) {\n\tsyncData(false, byHand)\n}\n\n// SyncDataBeforeEnableEncryptedNotebook 在启用加密笔记本前执行一次完整同步。\n// 未启用数据同步时直接返回；已启用数据同步时，任何同步失败都会阻止继续创建新的密钥体系。\nfunc SyncDataBeforeEnableEncryptedNotebook() error {\n\tif !Conf.Sync.Enabled {\n\t\treturn nil\n\t}\n\tif conf.ProviderS3 != Conf.Sync.Provider && !cloud.IsValidCloudDirName(Conf.Sync.CloudName) {\n\t\treturn errors.New(Conf.Language(123))\n\t}\n\tif !checkSync(false, false, true) {\n\t\treturn errors.New(Conf.Language(53))\n\t}\n\n\t// 不复用请求合并状态，确保调用返回前确实完成了一次由当前启用操作发起的完整同步。\n\tlockSync()\n\tdefer unlockSync()\n\tif err := syncDataLocked(false, true); err != nil {\n\t\tif Conf.Sync.Stat != \"\" {\n\t\t\treturn errors.New(Conf.Sync.Stat)\n\t\t}\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc lockSync() {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/sync.go#L219-L255","documentation":"SyncDataBeforeEnableEncryptedNotebook performs a forced sync before a new encryption key system is created. If sync is enabled but no valid cloud sync directory is configured (and the provider is not S3), it returns the localized message for language key 123: sync can only be activated after adding/selecting the cloud sync directory. Without a target directory the mandatory pre-enable sync cannot run, and proceeding could fork encrypted data.","triggerScenarios":"Calling EnableEncryptedNotebookWithSync (which invokes this) while Conf.Sync.Enabled is true but Conf.Sync.CloudName is empty or invalid and provider != S3.","commonSituations":"User enabled sync toggle but never picked a cloud directory; config file edited manually leaving CloudName blank; migrating config from another workspace where the directory name was lost.","solutions":["Open Settings - Sync and select/create a cloud sync directory before enabling the encrypted notebook","Set Conf.Sync.CloudName to a valid directory name (validated by cloud.IsValidCloudDirName)","Alternatively switch the provider to S3, which bypasses the cloud directory name requirement"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (window.siyuan.config.sync.enabled &&\n    window.siyuan.config.sync.provider !== 3 /* S3 */ &&\n    !window.siyuan.config.sync.cloudName) {\n  alert(\"Select a cloud sync directory first\");\n  return;\n}","typeGuard":null,"tryCatchPattern":"if err := model.SyncDataBeforeEnableEncryptedNotebook(); err != nil {\n    // surface Conf.Language(123)-style message; prompt user to pick a directory\n}","preventionTips":["Always configure the cloud sync directory before enabling encrypted notebooks","Check Conf.Sync.CloudName is non-empty when provider is not S3","Expose directory selection in the enable flow rather than calling the API directly"],"tags":["go","sync","configuration","encrypted-notebook"],"backgroundTag":"missing-required-config-field","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"}