siyuan-note/siyuan · error
read encrypted index setting
Error message
read encrypted index setting %s: %w
What it means
CheckEncryptedIndexCompatibility verifies that an encrypted SQLite index (SQLCipher-backed) exposes its cipher PRAGMA settings so the kernel can compare them against recorded compatibility metadata. This error wraps the underlying driver failure when reading one of the required PRAGMA values (cipher_version, cipher_page_size, kdf_iter, etc.). It means the connection could not answer the cipher introspection query, typically because the database is not opened with the SQLCipher driver or the key is wrong.
Solutions
- Verify the database is opened via OpenEncryptedDB/OpenEncryptedBlockTreeDB with the correct SQLCipher key, not a plain sqlite handle
- Check kernel logs for the wrapped driver error to distinguish wrong key vs wrong driver
- Confirm the database file is not corrupted (restore from sync/history rather than repairing by hand)
- Ensure the bundled SQLCipher fork (go-sqlite3 replace directive) is intact and the binary was rebuilt after dependency changes
Example fix
// before
db, err := sql.Open("sqlite3", path)
// after
db, err := util.OpenEncryptedDB(path, key) Defensive patterns
Strategy: try-catch
Validate before calling
if db == nil { return errors.New("db not initialized") }
// ensure the open path used the SQLCipher driver with a key before compatibility checks Try / catch
if err := util.CheckEncryptedIndexCompatibility(db, kind, schema); err != nil {
log.Printf("encrypted index unusable, rebuilding from source docs: %v", err)
// fall back to the authenticated rebuild path
} Prevention
- Always open encrypted indexes through OpenEncryptedDB/OpenEncryptedBlockTreeDB
- Keep the bundled SQLCipher fork and its replace directive intact
- Never open the same workspace DB with two kernel processes
- Restore corrupted indexes from sync/history instead of repairing by hand
When it happens
Trigger: Calling OpenEncryptedDB or OpenEncryptedBlockTreeDB with a database not actually encrypted with SQLCipher (the plain SQLite driver fails on PRAGMA cipher_*), or with an incorrect/wrong-format key so the cipher page cannot be read.
Common situations: Mixing plain mattn/go-sqlite3 with encrypted notebooks; corrupted database file after an interrupted write; opening a database created by a different SQLCipher version whose PRAGMAs are unsupported; wrong passphrase supplied at open time.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- missing encrypted index setting
- Conf.Language(381)
- encrypted blocktree db not opened for box
- encrypted box db not opened for box
- encrypted box db not opened for box
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/1f0416f9b535279f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/encrypted_index.go:21
// SPDX-License-Identifier: AGPL-3.0-or-later
package util
import (
"database/sql"
"encoding/json"
"errors"
"fmt"
)
// CheckEncryptedIndexCompatibility 将索引版本保存在受 SQLCipher 认证的表中,拒绝复用缺少版本或参数不匹配的旧索引。
// schema 由各索引维护,修改表结构时递增;索引重建由已认证源文档的调用方负责。
func CheckEncryptedIndexCompatibility(db *sql.DB, kind string, schema int) error {
settings := map[string]string{}
for _, name := range []string{"cipher_version", "cipher_page_size", "kdf_iter", "cipher_hmac_algorithm", "cipher_kdf_algorithm", "cipher_use_hmac"} {
var value string
if err := db.QueryRow("PRAGMA " + name).Scan(&value); err != nil {
return fmt.Errorf("read encrypted index setting %s: %w", name, err)
}
if value == "" {
return fmt.Errorf("missing encrypted index setting %s", name)
}
settings[name] = value
}
encoded, err := json.Marshal(settings)
if err != nil {
return err
}
var metadataTables int
if err = db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = 'encrypted_index_meta'").Scan(&metadataTables); err != nil {
return err
}
if metadataTables == 0 {
var tables int
if err = db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type = 'table'").Scan(&tables); err != nil {
return errView on GitHub (pinned to 9f775e8a12)