{"record":{"id":"fbd91571be090628","repo":"siyuan-note/siyuan","slug":"invalid-asset-download-mode","errorCode":null,"errorMessage":"invalid asset download mode","messagePattern":"invalid asset download mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/asset_download.go","lineNumber":300,"sourceCode":"\treturn nil\n}\n\n// clearAssetDownloadState 在旧密钥仍可认证且全部恢复内容齐全时清除设备状态。\nfunc clearAssetDownloadState() error {\n\texists, err := assetDownloadStateExists()\n\tif err != nil || !exists {\n\t\treturn err\n\t}\n\trepo, err := newRepositoryWithAssetSourceLocked()\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn repo.ClearAssetDownloadState()\n}\n\nfunc SetSyncAssetDownloadMode(mode int) error {\n\tif mode != 0 && mode != 1 {\n\t\treturn errors.New(\"invalid asset download mode\")\n\t}\n\tlockSync()\n\tdefer unlockSync()\n\tassetDownloadSourceMu.Lock()\n\tdefer assetDownloadSourceMu.Unlock()\n\tif mode == 0 {\n\t\tif err := ensureAllSyncAssets(); err != nil {\n\t\t\treturn err\n\t\t}\n\t\texists, err := assetDownloadStateExists()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif exists {\n\t\t\trepo, repoErr := newRepositoryWithAssetSourceLocked()\n\t\t\tif repoErr != nil {\n\t\t\t\treturn repoErr\n\t\t\t}","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/asset_download.go#L282-L318","documentation":"SetSyncAssetDownloadMode only accepts mode 0 (download on demand) or mode 1 (download all assets); any other integer is rejected with 'invalid asset download mode'. This is a strict enum validation on the mode parameter before any lock or state change.","triggerScenarios":"Calling the setSyncAssetDownloadMode API or the test helper with mode values other than 0 or 1, e.g. -1, 2, or a raw UI string coerced to a wrong integer.","commonSituations":"Plugin or script invoking the internal contract endpoint with an out-of-range value; frontend sending a checkbox value like 2 or a boolean encoded as an unexpected int; API misuse after a version that once accepted other values.","solutions":["Send exactly 0 (manual/on-demand) or 1 (download all) as the mode value","Clamp/validate the value at the caller boundary before invoking the API","If the frontend slider/checkbox produces other values, map them to 0/1 before the request"],"exampleFix":"// before\nsetSyncAssetDownloadMode(checkbox.checked ? 2 : 0)\n// after\nsetSyncAssetDownloadMode(checkbox.checked ? 1 : 0)","handlingStrategy":"validation","validationCode":"func validAssetDownloadMode(m int) bool { return m == 0 || m == 1 }","typeGuard":null,"tryCatchPattern":"if err := model.SetSyncAssetDownloadMode(m); err != nil && strings.Contains(err.Error(), \"invalid asset download mode\") {\n    m = 0 // fall back to on-demand\n}","preventionTips":["Constrain UI controls to emit exactly 0 or 1","Validate/clamp the mode at the API boundary before sending","Document the two supported values where the API is consumed"],"tags":["validation","enum","sync-config"],"backgroundTag":"invalid-enum-value","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"}