From e9a2dc2e4d2cfd8f362cb6cb99305705dc608abb Mon Sep 17 00:00:00 2001 From: Jeffrey Chen <78434827+TCOTC@users.noreply.github.com> Date: Mon, 13 Apr 2026 21:47:57 +0800 Subject: [PATCH] Add error details to the abnormal status pop-up window (#17465) * :art: Add error details to the abnormal status pop-up window * :art: Add error details to the abnormal status pop-up window --- app/src/dialog/processSystem.ts | 7 +++++-- app/src/index.ts | 2 +- app/src/mobile/util/onMessage.ts | 2 +- app/src/window/index.ts | 2 +- kernel/model/transaction.go | 29 +++++++++++++++++++++-------- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index 9d18f61df..7519c24ef 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -378,14 +378,17 @@ export const exitSiYuan = async (setCurrentWorkspace = true) => { }); }; -export const transactionError = () => { +export const transactionError = (msg?: string) => { if (document.getElementById("transactionError")) { return; } const dialog = new Dialog({ disableClose: true, title: `${window.siyuan.languages.stateExcepted} v${Constants.SIYUAN_VERSION}`, - content: `
${window.siyuan.languages.rebuildIndexTip}
+ content: `
+ ${window.siyuan.languages.rebuildIndexTip} + ${msg ? `
${escapeHtml(msg.trim())}
` : ""} +
diff --git a/app/src/index.ts b/app/src/index.ts index 07d70143e..cc86cfe78 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -188,7 +188,7 @@ export class App { downloadProgress(data.data); break; case "txerr": - transactionError(); + transactionError(data.msg); break; case "syncing": processSync(data, this.plugins); diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.ts index 99add9a90..3b80dcc87 100644 --- a/app/src/mobile/util/onMessage.ts +++ b/app/src/mobile/util/onMessage.ts @@ -92,7 +92,7 @@ export const onMessage = (app: App, data: IWebSocketData) => { openMobileFileById(app, data.data.id); break; case"txerr": - transactionError(); + transactionError(data.msg); break; case"statusbar": if (!document.querySelector("#keyboardToolbar").classList.contains("fn__none") || diff --git a/app/src/window/index.ts b/app/src/window/index.ts index e15f22c5a..db7c26637 100644 --- a/app/src/window/index.ts +++ b/app/src/window/index.ts @@ -144,7 +144,7 @@ class App { progressStatus(data); break; case "txerr": - transactionError(); + transactionError(data.msg); break; case "syncing": processSync(data, this.plugins); diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 162c9013f..644a5c786 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -92,8 +92,19 @@ func flushTx(tx *Transaction) { start := time.Now() if txErr := performTx(tx); nil != txErr { switch txErr.code { - case TxErrCodeBlockNotFound: - util.PushTxErr("Transaction failed", txErr.code, nil) + case TxErrCodeBlockNotFound, TxErrCodePushMsg: + pushMsg := txErr.msg + if pushMsg == "" { + if TxErrCodeBlockNotFound == txErr.code { + pushMsg = "Transaction failed: block not found" + } else { + pushMsg = "Transaction failed" + } + } + if txErr.id != "" && !strings.Contains(pushMsg, txErr.id) { + pushMsg += fmt.Sprintf(" [%s]", txErr.id) + } + util.PushTxErr(pushMsg, txErr.code, nil) return case TxErrCodeDataIsSyncing: util.PushMsg(Conf.Language(222), 5000) @@ -118,7 +129,6 @@ func PerformTransactions(transactions *[]*Transaction) { tx.m = &sync.Mutex{} txQueue <- tx } - return } const ( @@ -126,6 +136,7 @@ const ( TxErrCodeDataIsSyncing = 1 TxErrCodeWriteTree = 2 TxErrHandleAttributeView = 3 + TxErrCodePushMsg = 4 ) type TxErr struct { @@ -150,7 +161,7 @@ func performTx(tx *Transaction) (ret *TxErr) { return } logging.LogErrorf("begin tx failed: %s", err) - ret = &TxErr{msg: err.Error()} + ret = &TxErr{code: TxErrCodePushMsg, msg: err.Error()} return } @@ -332,7 +343,7 @@ func performTx(tx *Transaction) (ret *TxErr) { if cr := tx.commit(); nil != cr { logging.LogErrorf("commit tx failed: %s", cr) - return &TxErr{msg: cr.Error()} + return &TxErr{code: TxErrCodePushMsg, msg: cr.Error()} } return } @@ -1201,6 +1212,8 @@ func (tx *Transaction) doInsert0(operation *Operation, tree *parse.Tree) (ret *T insertedNode := subTree.Root.FirstChild if nil == insertedNode { + logging.LogErrorf("invalid data tree: insert op id[%s] parent[%s] previous[%s] next[%s] root[%s]", + operation.ID, operation.ParentID, operation.PreviousID, operation.NextID, tree.Root.ID) return &TxErr{code: TxErrCodeBlockNotFound, msg: "invalid data tree"} } var remains []*ast.Node @@ -1413,7 +1426,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) { oldNode := treenode.GetNodeInTree(tree, id) if nil == oldNode { logging.LogErrorf("get node [%s] in tree [%s] failed", id, tree.Root.ID) - return &TxErr{msg: ErrBlockNotFound.Error(), id: id} + return &TxErr{code: TxErrCodeBlockNotFound, msg: ErrBlockNotFound.Error(), id: id} } // 收集引用的定义块 ID @@ -1467,7 +1480,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) { updatedNode := subTree.Root.FirstChild if nil == updatedNode { logging.LogErrorf("get fist node in sub tree [%s] failed", subTree.Root.ID) - return &TxErr{msg: ErrBlockNotFound.Error(), id: id} + return &TxErr{code: TxErrCodeBlockNotFound, msg: ErrBlockNotFound.Error(), id: id} } if ast.NodeList == updatedNode.Type && ast.NodeList == oldNode.Parent.Type { updatedNode = updatedNode.FirstChild @@ -1718,7 +1731,7 @@ func (tx *Transaction) doUpdateUpdated(operation *Operation) (ret *TxErr) { node := treenode.GetNodeInTree(tree, id) if nil == node { logging.LogErrorf("get node [%s] in tree [%s] failed", id, tree.Root.ID) - return &TxErr{msg: ErrBlockNotFound.Error(), id: id} + return &TxErr{code: TxErrCodeBlockNotFound, msg: ErrBlockNotFound.Error(), id: id} } node.SetIALAttr("updated", operation.Data.(string))