siyuan-note/siyuan · error

encrypted notebook cannot be saved as a normal notebook

Error message

encrypted notebook cannot be saved as a normal notebook

What it means

This error prevents silently converting an encrypted notebook back to a normal (unencrypted) one. When the incoming conf has Encrypted=false but the notebook on disk is still registered as encrypted (IsEncryptedBox), saving would drop encryption state, so the save is rejected. Encryption removal requires the explicit unencrypt flow, not a plain conf save.

Solutions

  1. Preserve the existing Encrypted=true field when building the BoxConf to save (copy it from the current box conf)
  2. If decryption is truly intended, use the dedicated unencrypt/remove-encryption flow instead of SaveConf
  3. Check IsEncryptedBox(boxID) before saving and merge the incoming conf with the persisted encryption state

Example fix

// before
incoming := &conf.BoxConf{Icon: icon, Sort: sort} // Encrypted lost
conf.SaveConf(boxID, incoming)
// after
existing := Conf.GetBox(boxID)
incoming.Encrypted = existing.Encrypted
conf.SaveConf(boxID, incoming)
Defensive patterns

Strategy: validation

Validate before calling

if !incoming.Encrypted && IsEncryptedBox(boxID) {
    // do not save; route to the explicit unencrypt flow
}

Try / catch

if _, err := prepareBoxConfForSave(boxID, boxConf); err != nil && strings.Contains(err.Error(), "cannot be saved as a normal notebook") {
    // preserve Encrypted=true and merge instead of overwriting
}

Prevention

When it happens

Trigger: SaveConf called with a BoxConf whose Encrypted flag is false while IsEncryptedBox(boxID) returns true — e.g. a caller builds a fresh conf struct without preserving the Encrypted field, or UI code toggles encryption off directly through conf save.

Common situations: Plugin/API clients constructing BoxConf from scratch and defaulting Encrypted=false; syncing or importing conf fragments from a non-encrypted workspace; a bug that loses the Encrypted flag across a conf copy.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/530f5dff252d4cdc. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/box_conf_crypto.go:99

	if err := decryptBoxMetadata(boxID, boxConf, dek); err != nil {
		setEncryptedBoxState(boxID, EncryptedBoxStateError)
		return err
	}
	return nil
}

func prepareBoxConfForSave(boxID string, boxConf *conf.BoxConf) (*conf.BoxConf, error) {
	if boxConf == nil {
		return nil, errors.New("notebook configuration is missing")
	}
	persisted := *boxConf
	persisted.BoxCrypt = DeepCopyBoxEncryption(boxConf.BoxCrypt)
	if persisted.Encrypted {
		forgetRuntimeNormalBox(boxID)
	}
	if !persisted.Encrypted {
		if IsEncryptedBox(boxID) {
			return nil, errors.New("encrypted notebook cannot be saved as a normal notebook")
		}
		return &persisted, nil
	}
	if persisted.BoxCrypt == nil {
		clearBoxMetadata(&persisted)
		return &persisted, nil
	}
	if GetEncryptedBoxState(boxID) == EncryptedBoxStateError {
		return nil, errors.New("encrypted notebook is in an error state")
	}

	if dek, ok := cachedDEKCopy(boxID); ok {
		defer zeroAndClear(dek)
		if err := reuseBoxMetadataIfUnchanged(boxID, &persisted, dek); err != nil {
			return nil, err
		}
	} else if len(persisted.BoxCrypt.Metadata) == 0 {
		existing, err := readRawBoxConf(boxID)

View on GitHub (pinned to 9f775e8a12)