Add error details to the abnormal status pop-up window (#17465)

* 🎨 Add error details to the abnormal status pop-up window

* 🎨 Add error details to the abnormal status pop-up window
This commit is contained in:
Jeffrey Chen 2026-04-13 21:47:57 +08:00 committed by GitHub
parent 08ef8f37f6
commit e9a2dc2e4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 13 deletions

View file

@ -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: `<div class="b3-dialog__content" id="transactionError">${window.siyuan.languages.rebuildIndexTip}</div>
content: `<div class="b3-dialog__content" id="transactionError">
${window.siyuan.languages.rebuildIndexTip}
${msg ? `<br><div style="margin-top: 8px; max-height: 50vh; white-space: pre-wrap;">${escapeHtml(msg.trim())}</div>` : ""}
</div>
<div class="b3-dialog__action">
<button class="b3-button b3-button--text">${window.siyuan.languages._kernel[97]}</button>
<div class="fn__space"></div>

View file

@ -188,7 +188,7 @@ export class App {
downloadProgress(data.data);
break;
case "txerr":
transactionError();
transactionError(data.msg);
break;
case "syncing":
processSync(data, this.plugins);

View file

@ -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") ||

View file

@ -144,7 +144,7 @@ class App {
progressStatus(data);
break;
case "txerr":
transactionError();
transactionError(data.msg);
break;
case "syncing":
processSync(data, this.plugins);

View file

@ -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))