siyuan-note/siyuan · error

Conf.Language(314)

Error message

Conf.Language(314)

What it means

copyAssetDecryptIfEncrypted copies an asset file from a notebook to an export destination, decrypting it first when the source notebook is an encrypted box. When GetDEKIfUnlocked cannot return the box's data-encryption key, the notebook is locked (or its key state is unavailable), and the function fail-closes: it refuses to copy ciphertext or placeholder data to the export directory to avoid leaking unusable/invalid files, returning the localized message 314 ('Please unlock the encrypted notebook first').

Solutions

  1. Unlock the encrypted notebook in the UI (enter the notebook password) so its DEK is cached, then retry the export/copy.
  2. If exporting programmatically, call the unlock API for the target box before triggering the export.
  3. If the notebook should not be encrypted, remove encryption from the notebook so assets copy in plaintext.
  4. Check GetDEKIfUnlocked/box lock state if you believe the notebook is unlocked (lock was lost, e.g. after kernel restart).

Example fix

// before: export fails with Conf.Language(314)
exportDoc(exportPath, boxID)
// after: ensure the box is unlocked first
if err := UnlockBox(boxID, password); err != nil { return err }
exportDoc(exportPath, boxID)
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: check unlock state before exporting assets from an encrypted box
de, err := model.GetDEKIfUnlocked(boxID)
if err != nil {
    // notebook locked: prompt user to unlock before exporting
    return fmt.Errorf("unlock notebook %s first", boxID)
}

Try / catch

err := exportDoc(path)
if err != nil && err.Error() == conf.Language(314) {
    // show unlock dialog, then retry export
    promptUnlock(boxID)
}

Prevention

When it happens

Trigger: Exporting/copying assets (e.g. export document, copy asset) whose srcPath resolves via ExtractBoxIDFromAssetsPath to an encrypted box (IsEncryptedBox(boxID) true) while the box's DEK is not cached because the user has not unlocked the notebook since kernel start, or the unlock session expired/was cleared.

Common situations: User restarts SiYuan (encrypted notebooks start locked) and then exports a document containing assets from an encrypted notebook; automated export via API/script without prior unlock; unlocking only one of several encrypted boxes and exporting assets from another; enabling encryption on an existing notebook but not completing the unlock dialog.

Related errors


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

Appendix: source

Thrown at kernel/model/crypto.go:2584

	return &crypt, nil
}

// copyAssetDecryptIfEncrypted 把 srcPath 的 asset 复制到 destPath。
// 若 srcPath 在已解锁的加密笔记本下,读密文→解密→写明文到 destPath(导出目录);
// 否则走 filelock.Copy 原路径(字节级复制,密文/明文均可)。
func copyAssetDecryptIfEncrypted(srcPath, destPath string) error {
	if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil {
		return err
	}

	boxID := ExtractBoxIDFromAssetsPath(srcPath)
	if boxID != "" && IsEncryptedBox(boxID) {
		HoldBoxReadLock(boxID)
		defer ReleaseBoxReadLock(boxID)
		dek, err := GetDEKIfUnlocked(boxID)
		if err != nil {
			// 加密笔记本未解锁:fail-closed,拒绝复制(不复制密文,避免泄漏无效文件)
			return errors.New(Conf.Language(314))
		}
		raw, readErr := filelock.ReadFile(srcPath)
		if readErr != nil {
			return readErr
		}
		diskName := filepath.Base(srcPath)
		plain, decErr := DecryptAsset(boxID, diskName, dek, raw)
		if decErr != nil {
			return errors.New(Conf.Language(316))
		}
		if err := filelock.WriteFile(destPath, plain); err != nil {
			return err
		}
		return nil
	}
	return filelock.Copy(srcPath, destPath)
}

View on GitHub (pinned to 9f775e8a12)