{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/asset_download.go#L282-L318","documentation":"SetSyncAssetDownloadMode validation: the requested asset download mode integer is neither 0 (full/download mode) nor 1 (on-demand). Only these two enumerated modes exist for encrypted-notebook asset download; any other value is refused before touching sync state.","triggerScenarios":"Calling SetSyncAssetDownloadMode with a value other than 0 or 1, e.g. -1, 2, or an uninitialized int variable.","commonSituations":"Plugin/kernel API callers guessing mode values; config fields defaulting to a non-0/1 value; tests passing raw integers instead of named constants.","solutions":["Pass exactly 0 (disabled) or 1 (enabled)","Clamp/validate the mode value before calling","Initialize config fields to 0 rather than leaving them unset"],"exampleFix":"// before\nmode := cfg.AssetDownloadMode // could be -1\nerr := model.SetSyncAssetDownloadMode(mode)\n// after\nif mode != 0 && mode != 1 { mode = 0 }\nerr := model.SetSyncAssetDownloadMode(mode)","handlingStrategy":"validation","validationCode":"if mode !== 0 && mode !== 1 { throw new Error(\"mode must be 0 or 1\") }\nmodel.SetSyncAssetDownloadMode(mode);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use named constants ASSET_DOWNLOAD_OFF=0 / ON=1 instead of raw ints","Validate external/plugin input before calling SetSyncAssetDownloadMode","Initialize persisted config fields to 0"],"tags":["validation","enum","sync","api-misuse"],"backgroundTag":"invalid-enum-value","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}