siyuan-note/siyuan · error
Conf.Language(312)
Error message
Conf.Language(312)
What it means
EnableEncryptedNotebook refuses to run when the encrypted-notebook feature is already fully configured, returning the localized message Conf.Language(312) ("encryption is already enabled"). Re-running enablement would overwrite the existing MasterSalt/KEK parameters and destroy access to already-encrypted notebooks, so the guard returns this user-facing error instead.
Solutions
- Before calling, check Conf.NotebookCrypto.Enabled (and completeness) and skip the call if already enabled
- Treat this error as success in idempotent flows: if the state is 'already enabled', proceed without re-enabling
- If you actually need to change/recover the key material, use the recovery/restore path (tryRestoreNotebookCryptoFromBackup) rather than re-enabling
- In tests, reset or disable NotebookCrypto config between test cases
Example fix
// before
err := model.EnableEncryptedNotebook(password)
// after
if Conf.NotebookCrypto.Enabled && model.NotebookCryptoConfigurationComplete(Conf.NotebookCrypto) {
return nil // already enabled; nothing to do
}
err := model.EnableEncryptedNotebook(password) Defensive patterns
Strategy: try-catch
Validate before calling
if Conf.NotebookCrypto.Enabled && model.NotebookCryptoConfigurationComplete(Conf.NotebookCrypto) {
return nil // already enabled, skip
} Try / catch
if err := model.EnableEncryptedNotebook(password); err != nil {
if err.Error() == model.Conf.Language(312) {
return nil // idempotent: already enabled
}
return err
} Prevention
- Make enable flows idempotent: treat 'already enabled' as success
- Check the Enabled flag before invoking enable APIs
- Avoid re-running bootstrap scripts against an already-configured workspace
- For key changes or loss, use the recovery/restore path, never re-enable
When it happens
Trigger: Calling EnableEncryptedNotebook (directly or via EnableEncryptedNotebookWithSync) when Conf.NotebookCrypto.Enabled is true and notebookCryptoConfigurationComplete(¤t) reports the config has MasterSalt/verification data — e.g. double-invoking the enable API, clicking the enable action twice in the UI, or enabling on a workspace where encryption was set up previously.
Common situations: A second device or a re-run script calls the enable endpoint against an already-encrypted workspace; a UI flow retries the call after a timeout not knowing the first call succeeded; tests call EnableEncryptedNotebook twice without resetting the config between cases.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- 314
- 314
- conditional replacement of encrypted attribute views is not…
- Conf.Language(12)
- Conf.Language(313)
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/00eebf53d20ab848.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:1008
return EnableEncryptedNotebook(password)
}
// EnableEncryptedNotebook 启用加密笔记本功能:生成 MasterSalt、派生 KEK、写入校验值并持久化。
// 重复调用(已启用)返回错误,避免覆盖现有加密笔记本的密钥参数。
// KEK 不缓存——启用后用户需对每个加密笔记本单独调 UnlockBox 解锁。
func EnableEncryptedNotebook(password string) error {
if len(password) == 0 {
return errors.New("password must not be empty")
}
notebookCryptoMu.Lock()
defer notebookCryptoMu.Unlock()
Conf.m.RLock()
current := *Conf.NotebookCrypto
Conf.m.RUnlock()
if current.Enabled && notebookCryptoConfigurationComplete(¤t) {
return errors.New(Conf.Language(312))
}
hasEncrypted, listErr := hasEncryptedNotebook()
if listErr != nil {
return fmt.Errorf("list encrypted notebooks failed: %w", listErr)
}
hasHistory, historyErr := scanEncryptedNotebookHistory()
if historyErr != nil {
return fmt.Errorf("check encrypted notebook history failed: %w", historyErr)
}
hasBackup := filelock.IsExist(dataCryptoBackupPath())
if hasEncrypted || hasHistory || hasBackup {
// 现存笔记本、已删除笔记本历史或全局备份均表示已有密钥域,必须恢复并认证,不能生成新 MasterSalt。
kek, restoreErr := tryRestoreNotebookCryptoFromBackupLocked(password)
if kek != nil {
zeroAndClear(kek)
}
if restoreErr != nil {View on GitHub (pinned to 9f775e8a12)