diff --git a/app/electron/main.js b/app/electron/main.js index 49daf94c7..1fee5957a 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -582,7 +582,7 @@ const initKernel = (workspace, port, lang) => { let errorWindowId; switch (code) { case 20: - errorWindowId = showErrorWindow("数据库被锁定", "The database is locked", "
数据库文件正在被其他进程占用,请检查是否同时存在多个内核进程(SiYuan Kernel)服务相同的工作空间。
The database file is being occupied by other processes, please check whether there are multiple kernel processes (SiYuan Kernel) serving the same workspace at the same time.
"); + errorWindowId = showErrorWindow("数据库不可用", "The database is unavailable", "
无法访问数据库文件,请查看 工作空间/temp/siyuan.log 获取详细报错信息
Cannot access the database file. Please check workspace/temp/siyuan.log for detailed error information.
"); break; case 21: errorWindowId = showErrorWindow("监听端口 " + currentKernelPort + " 失败", "Failed to listen to port " + currentKernelPort, "
监听 " + currentKernelPort + " 端口失败,请确保程序拥有网络权限并不受防火墙和杀毒软件阻止。
Failed to listen to port " + currentKernelPort + ", please make sure the program has network permissions and is not blocked by firewalls and antivirus software.
"); diff --git a/kernel/go.mod b/kernel/go.mod index f6659e2c0..c4161f972 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -64,7 +64,7 @@ require ( github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97 github.com/siyuan-note/filelock v0.0.0-20251212095217-08318833e008 github.com/siyuan-note/httpclient v0.0.0-20260115093840-2754d8028f22 - github.com/siyuan-note/logging v0.0.0-20251209020516-52f1a2f65ec5 + github.com/siyuan-note/logging v0.0.0-20260117134552-88b424dfe7f1 github.com/siyuan-note/riff v0.0.0-20251022131846-228528e70754 github.com/spf13/cast v1.10.0 github.com/steambap/captcha v1.4.1 diff --git a/kernel/go.sum b/kernel/go.sum index e58134834..df0a1e6ce 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -389,8 +389,8 @@ github.com/siyuan-note/filelock v0.0.0-20251212095217-08318833e008 h1:3wEmNS4eZk github.com/siyuan-note/filelock v0.0.0-20251212095217-08318833e008/go.mod h1:9OhXAyOkSXwuLvNCZk2aFMo0nOldyO3f2hMJEnkuT30= github.com/siyuan-note/httpclient v0.0.0-20260115093840-2754d8028f22 h1:6k8Yz4Qcoi2xAxNbb45FJ39LlX8eKLt7KqPvQ/4YEtQ= github.com/siyuan-note/httpclient v0.0.0-20260115093840-2754d8028f22/go.mod h1:7ID0NNsYc+i9oCJCshnjLd67FgxLLm+eBfhb5Ul7LlU= -github.com/siyuan-note/logging v0.0.0-20251209020516-52f1a2f65ec5 h1:bIMoJAAf3tV0xYcN+N2Vw7Ot/LbVxuz715o1rn1GDto= -github.com/siyuan-note/logging v0.0.0-20251209020516-52f1a2f65ec5/go.mod h1:U6DyWKvtIPW9WrUoUikPCwFUzUoHGtEJjjeLNYae1nc= +github.com/siyuan-note/logging v0.0.0-20260117134552-88b424dfe7f1 h1:C2Y1XhBrrGegnHvWOeVVRFkMRzB6EqJSytHheq+T6mU= +github.com/siyuan-note/logging v0.0.0-20260117134552-88b424dfe7f1/go.mod h1:t3Tmt3DgQx0zqJmrckszJ+JBZ7iJrD1Ktp8FDBQ249E= github.com/siyuan-note/riff v0.0.0-20251022131846-228528e70754 h1:6QYpy7s5HlRSge09TyM/mT0vz1RDcWYZdkxEh7hmbH4= github.com/siyuan-note/riff v0.0.0-20251022131846-228528e70754/go.mod h1:/N7+N2CsZ0nleNPpP3b+06Bzqvuhy6GUmLY7Kug/zT0= github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= diff --git a/kernel/model/box.go b/kernel/model/box.go index 850dfb551..d294b7d21 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -822,7 +822,7 @@ func fullReindex() { FlushTxQueue() if err := sql.InitDatabase(true); err != nil { - os.Exit(logging.ExitCodeReadOnlyDatabase) + os.Exit(logging.ExitCodeUnavailableDatabase) return } diff --git a/kernel/sql/database.go b/kernel/sql/database.go index 4ca364b8f..82f1240c9 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -114,115 +114,115 @@ func InitDatabase(forceRebuild bool) (err error) { func initDBTables() { _, err := db.Exec("DROP TABLE IF EXISTS stat") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [stat] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [stat] failed: %s", err) } _, err = db.Exec("CREATE TABLE stat (key, value)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [stat] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [stat] failed: %s", err) } setDatabaseVer() _, err = db.Exec("DROP TABLE IF EXISTS blocks") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [blocks] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [blocks] failed: %s", err) } _, err = db.Exec("CREATE TABLE blocks (id, parent_id, root_id, hash, box, path, hpath, name, alias, memo, tag, content, fcontent, markdown, length, type, subtype, ial, sort, created, updated)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [blocks] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [blocks] failed: %s", err) } _, err = db.Exec("CREATE INDEX idx_blocks_id ON blocks(id)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create index [idx_blocks_id] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create index [idx_blocks_id] failed: %s", err) } _, err = db.Exec("CREATE INDEX idx_blocks_parent_id ON blocks(parent_id)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create index [idx_blocks_parent_id] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create index [idx_blocks_parent_id] failed: %s", err) } _, err = db.Exec("CREATE INDEX idx_blocks_root_id ON blocks(root_id)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create index [idx_blocks_root_id] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create index [idx_blocks_root_id] failed: %s", err) } _, err = db.Exec("DROP TABLE IF EXISTS blocks_fts") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [blocks_fts] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [blocks_fts] failed: %s", err) } _, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan\")") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [blocks_fts] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [blocks_fts] failed: %s", err) } _, err = db.Exec("DROP TABLE IF EXISTS blocks_fts_case_insensitive") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [blocks_fts_case_insensitive] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [blocks_fts_case_insensitive] failed: %s", err) } _, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts_case_insensitive USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan case_insensitive\")") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [blocks_fts_case_insensitive] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [blocks_fts_case_insensitive] failed: %s", err) } _, err = db.Exec("DROP TABLE IF EXISTS spans") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [spans] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [spans] failed: %s", err) } _, err = db.Exec("CREATE TABLE spans (id, block_id, root_id, box, path, content, markdown, type, ial)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [spans] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [spans] failed: %s", err) } _, err = db.Exec("CREATE INDEX idx_spans_root_id ON spans(root_id)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create index [idx_spans_root_id] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create index [idx_spans_root_id] failed: %s", err) } _, err = db.Exec("DROP TABLE IF EXISTS assets") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [assets] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [assets] failed: %s", err) } _, err = db.Exec("CREATE TABLE assets (id, block_id, root_id, box, docpath, path, name, title, hash)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [assets] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [assets] failed: %s", err) } _, err = db.Exec("CREATE INDEX idx_assets_root_id ON assets(root_id)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create index [idx_assets_root_id] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create index [idx_assets_root_id] failed: %s", err) } _, err = db.Exec("DROP TABLE IF EXISTS attributes") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [attributes] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [attributes] failed: %s", err) } _, err = db.Exec("CREATE TABLE attributes (id, name, value, type, block_id, root_id, box, path)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [attributes] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [attributes] failed: %s", err) } _, err = db.Exec("CREATE INDEX idx_attributes_block_id ON attributes(block_id)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create index [idx_attributes_block_id] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create index [idx_attributes_block_id] failed: %s", err) } _, err = db.Exec("CREATE INDEX idx_attributes_root_id ON attributes(root_id)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create index [idx_attributes_root_id] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create index [idx_attributes_root_id] failed: %s", err) } _, err = db.Exec("DROP TABLE IF EXISTS refs") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [refs] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [refs] failed: %s", err) } _, err = db.Exec("CREATE TABLE refs (id, def_block_id, def_block_parent_id, def_block_root_id, def_block_path, block_id, root_id, box, path, content, markdown, type)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [refs] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [refs] failed: %s", err) } _, err = db.Exec("DROP TABLE IF EXISTS file_annotation_refs") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [refs] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [refs] failed: %s", err) } _, err = db.Exec("CREATE TABLE file_annotation_refs (id, file_path, annotation_id, block_id, root_id, box, path, content, type)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [refs] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [refs] failed: %s", err) } } @@ -245,7 +245,7 @@ func initDBConnection() { var err error db, err = sql.Open("sqlite3_extended", dsn) if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create database failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create database failed: %s", err) } db.SetMaxIdleConns(20) db.SetMaxOpenConns(20) @@ -293,7 +293,7 @@ func initHistoryDBConnection() { var err error historyDB, err = sql.Open("sqlite3_extended", dsn) if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create history database failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create history database failed: %s", err) } historyDB.SetMaxIdleConns(3) historyDB.SetMaxOpenConns(3) @@ -304,7 +304,7 @@ func initHistoryDBTables() { historyDB.Exec("DROP TABLE histories_fts_case_insensitive") _, err := historyDB.Exec("CREATE VIRTUAL TABLE histories_fts_case_insensitive USING fts5(id UNINDEXED, type UNINDEXED, op UNINDEXED, title, content, path UNINDEXED, created UNINDEXED, tokenize=\"siyuan case_insensitive\")") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [histories_fts_case_insensitive] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [histories_fts_case_insensitive] failed: %s", err) } } @@ -349,7 +349,7 @@ func initAssetContentDBConnection() { var err error assetContentDB, err = sql.Open("sqlite3_extended", dsn) if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create assets database failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create assets database failed: %s", err) } assetContentDB.SetMaxIdleConns(3) assetContentDB.SetMaxOpenConns(3) @@ -360,7 +360,7 @@ func initAssetContentDBTables() { assetContentDB.Exec("DROP TABLE asset_contents_fts_case_insensitive") _, err := assetContentDB.Exec("CREATE VIRTUAL TABLE asset_contents_fts_case_insensitive USING fts5(id UNINDEXED, name, ext, path, size UNINDEXED, updated UNINDEXED, content, tokenize=\"siyuan case_insensitive\")") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [asset_contents_fts_case_insensitive] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [asset_contents_fts_case_insensitive] failed: %s", err) } } @@ -1345,7 +1345,7 @@ func beginTx() (tx *sql.Tx, err error) { if tx, err = db.Begin(); err != nil { logging.LogErrorf("begin tx failed: %s\n %s", err, logging.ShortStack()) if strings.Contains(err.Error(), "database is locked") { - os.Exit(logging.ExitCodeReadOnlyDatabase) + os.Exit(logging.ExitCodeUnavailableDatabase) } } return @@ -1369,7 +1369,7 @@ func beginHistoryTx() (tx *sql.Tx, err error) { if tx, err = historyDB.Begin(); err != nil { logging.LogErrorf("begin history tx failed: %s\n %s", err, logging.ShortStack()) if strings.Contains(err.Error(), "database is locked") { - os.Exit(logging.ExitCodeReadOnlyDatabase) + os.Exit(logging.ExitCodeUnavailableDatabase) } } return @@ -1393,7 +1393,7 @@ func beginAssetContentTx() (tx *sql.Tx, err error) { if tx, err = assetContentDB.Begin(); err != nil { logging.LogErrorf("begin asset content tx failed: %s\n %s", err, logging.ShortStack()) if strings.Contains(err.Error(), "database is locked") { - os.Exit(logging.ExitCodeReadOnlyDatabase) + os.Exit(logging.ExitCodeUnavailableDatabase) } } return @@ -1479,7 +1479,7 @@ func prepareExecInsertTx(tx *sql.Tx, stmtSQL string, args []interface{}) (err er tx.Rollback() closeDatabase() removeDatabaseFile() - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "database disk image [%s] is malformed, please restart SiYuan kernel to rebuild it", util.DBPath) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "database disk image [%s] is malformed, please restart SiYuan kernel to rebuild it", util.DBPath) } logging.LogErrorf("exec database stmt [%s] failed: %s\n %s", stmtSQL, err, logging.ShortStack()) return @@ -1493,7 +1493,7 @@ func execStmtTx(tx *sql.Tx, stmt string, args ...interface{}) (err error) { tx.Rollback() closeDatabase() removeDatabaseFile() - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "database disk image [%s] is malformed, please restart SiYuan kernel to rebuild it", util.DBPath) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "database disk image [%s] is malformed, please restart SiYuan kernel to rebuild it", util.DBPath) } logging.LogErrorf("exec database stmt [%s] failed: %s\n %s", stmt, err, logging.ShortStack()) return diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go index f5b3efaa3..c0b0b89e2 100644 --- a/kernel/treenode/blocktree.go +++ b/kernel/treenode/blocktree.go @@ -79,16 +79,16 @@ func initDatabase(forceRebuild bool) (err error) { func initDBTables() { _, err := db.Exec("DROP TABLE IF EXISTS blocktrees") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [blocks] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "drop table [blocks] failed: %s", err) } _, err = db.Exec("CREATE TABLE blocktrees (id, root_id, parent_id, box_id, path, hpath, updated, type)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [blocktrees] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create table [blocktrees] failed: %s", err) } _, err = db.Exec("CREATE INDEX idx_blocktrees_id ON blocktrees(id)") if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create index [idx_blocktrees_id] failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create index [idx_blocktrees_id] failed: %s", err) } } @@ -111,7 +111,7 @@ func initDBConnection() { var err error db, err = sql.Open("sqlite3_extended", dsn) if err != nil { - logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create database failed: %s", err) + logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "create database failed: %s", err) } db.SetMaxIdleConns(7) db.SetMaxOpenConns(7) @@ -654,7 +654,7 @@ func InitBlockTree(force bool) { err := initDatabase(force) if err != nil { logging.LogErrorf("init database failed: %s", err) - os.Exit(logging.ExitCodeReadOnlyDatabase) + os.Exit(logging.ExitCodeUnavailableDatabase) return } return