siyuan-note/siyuan · error

Conf.Language(314)

Error message

Conf.Language(314)

What it means

writeImportedTree writes a document file into the target notebook. If the box is encrypted, it first obtains the notebook's data encryption key with GetDEKIfUnlocked; when the notebook is locked (key unavailable), it returns i18n key 314: "Please unlock the encrypted notebook first". The write is deliberately refused instead of silently writing plaintext or failing cryptographically.

Solutions

  1. Unlock the encrypted notebook in the SiYuan UI (enter its passphrase) and retry the import.
  2. Unlock the notebook programmatically first via the unlock API for that box, then call the import endpoint.
  3. Import into a non-encrypted notebook if unlocking is not possible.

Example fix

// before: POST /api/import/importSY while box locked -> Conf.Language(314)
// after: unlock first
await fetch("/api/notebook/unlockEncryptedNotebook", { method: "POST", body: JSON.stringify({ notebook: boxID, password }) });
await fetch("/api/import/importSY", { method: "POST", body: JSON.stringify({ notebook: boxID, path: zipPath }) });
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the notebook is unlocked before import
await fetch("/api/notebook/lsNotebooks").then(r => r.json()).then(r => { const b = r.data.notebooks.find(n => n.id === boxID); if (b && b.closed) throw new Error("notebook locked"); });

Try / catch

try { await importSY(boxID, zipPath); } catch (e) { if (e.msg.includes("unlock the encrypted notebook")) { await unlockEncryptedNotebook(boxID, password); await importSY(boxID, zipPath); } else throw e; }

Prevention

When it happens

Trigger: importSY0 -> writeImportedTree on an IsEncryptedBox box while GetDEKIfUnlocked fails (user has locked the notebook, or the key/passphrase is unavailable in the current session).

Common situations: Importing a .sy.zip into an encrypted notebook that was locked after inactivity or at boot; scripted imports running before the user unlocked the notebook in the UI.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/e776891796251f9c. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/import.go:1177

		if err = filelock.Copy(assetsDir, dataAssets); err != nil {
			logging.LogErrorf("copy assets from [%s] to [%s] failed: %s", assetsDir, dataAssets, err)
			return nil, err
		}
		if removeErr := os.RemoveAll(assetsDir); removeErr != nil {
			return nil, removeErr
		}
	}
	return assetPathMap, nil
}

func writeImportedTree(boxID, syPath, newSyPath, relPath string, data []byte) error {
	if IsEncryptedBox(boxID) {
		HoldBoxReadLock(boxID)
		defer ReleaseBoxReadLock(boxID)

		dek, err := GetDEKIfUnlocked(boxID)
		if err != nil {
			return errors.New(Conf.Language(314))
		}
		data, err = EncryptFile(boxID, relPath, dek, data)
		if err != nil {
			return err
		}
	}
	if err := os.WriteFile(syPath, data, 0644); err != nil {
		return err
	}
	return filelock.Rename(syPath, newSyPath)
}

func validateImportedNotebookIdentities(tmpDataPath string) ([]string, error) {
	dirs, err := os.ReadDir(tmpDataPath)
	if err != nil {
		return nil, err
	}

View on GitHub (pinned to 8641553a1f)