siyuan-note/siyuan · error

encrypted notebook is in an error state

Error message

encrypted notebook is in an error state

What it means

The encrypted notebook's runtime state is marked EncryptedBoxStateError — an earlier decrypt/unlock step already failed — so prepareBoxConfForSave refuses to persist a new conf to avoid writing data derived from a broken encryption state. The save is aborted until the notebook's encryption state is fixed.

Solutions

  1. Re-unlock the notebook with the correct passphrase to clear the error state and repopulate the DEK cache
  2. Restore the notebook's .siyuan config/metadata from a known-good backup, then retry
  3. Restart the kernel and retry in case the error state came from a transient decryption failure
  4. If the notebook's encryption state is unrecoverable, use the documented recovery/migration path rather than forcing a save
Defensive patterns

Strategy: try-catch

Validate before calling

if GetEncryptedBoxState(boxID) == EncryptedBoxStateError {
    // require unlock/recovery before any save
}

Try / catch

_, err := prepareBoxConfForSave(boxID, boxConf)
if err != nil && GetEncryptedBoxState(boxID) == EncryptedBoxStateError {
    // surface recovery UI: re-enter passphrase or restore backup
}

Prevention

When it happens

Trigger: SaveConf on a notebook for which GetEncryptedBoxState(boxID)==EncryptedBoxStateError, typically set by revealBoxMetadataIfUnlocked or unlockBoxHeld after a decryption/AAD verification failure earlier in the session.

Common situations: User entered a wrong passphrase earlier leaving the box in error state; metadata ciphertext corrupted; key material mismatch after restoring data from a different workspace without its keys.

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


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

Appendix: source

Thrown at kernel/model/box_conf_crypto.go:108

		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)
		if err != nil {
			return nil, err
		}
		if existing == nil || existing.BoxCrypt == nil || len(existing.BoxCrypt.Metadata) == 0 {
			return nil, errors.New("encrypted notebook metadata is missing")
		}
		persisted.BoxCrypt.Metadata = append([]byte(nil), existing.BoxCrypt.Metadata...)
	}
	if err := validateBoxEncryption(persisted.BoxCrypt); err != nil {

View on GitHub (pinned to 9f775e8a12)