siyuan-note/siyuan · error
invalid asset download mode
Error message
invalid asset download mode
What it means
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.
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
Example fix
// before setSyncAssetDownloadMode(checkbox.checked ? 2 : 0) // after setSyncAssetDownloadMode(checkbox.checked ? 1 : 0)
Defensive patterns
Strategy: validation
Validate before calling
func validAssetDownloadMode(m int) bool { return m == 0 || m == 1 } Try / catch
if err := model.SetSyncAssetDownloadMode(m); err != nil && strings.Contains(err.Error(), "invalid asset download mode") {
m = 0 // fall back to on-demand
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ErrInvalidColumnAlign
- Field [mode] must be 0 or 1
- Field [ ] has an invalid value
- invalid block ref check scope
- invalid card aspect ratio preset
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/fbd91571be090628.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/asset_download.go:300
return nil
}
// clearAssetDownloadState 在旧密钥仍可认证且全部恢复内容齐全时清除设备状态。
func clearAssetDownloadState() error {
exists, err := assetDownloadStateExists()
if err != nil || !exists {
return err
}
repo, err := newRepositoryWithAssetSourceLocked()
if err != nil {
return err
}
return repo.ClearAssetDownloadState()
}
func SetSyncAssetDownloadMode(mode int) error {
if mode != 0 && mode != 1 {
return errors.New("invalid asset download mode")
}
lockSync()
defer unlockSync()
assetDownloadSourceMu.Lock()
defer assetDownloadSourceMu.Unlock()
if mode == 0 {
if err := ensureAllSyncAssets(); err != nil {
return err
}
exists, err := assetDownloadStateExists()
if err != nil {
return err
}
if exists {
repo, repoErr := newRepositoryWithAssetSourceLocked()
if repoErr != nil {
return repoErr
}View on GitHub (pinned to 9f775e8a12)