feat: 添加全局错误日志捕获
- Python 侧 _dispatch 异常时输出完整堆栈到 stderr - Go 侧 handler 返回 error 时打印日志 - 升级 Python 包版本至 0.1.4
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -105,6 +106,7 @@ func readResult(ctx context.Context, conn net.Conn, pool Pool, write func(Messag
|
|||||||
result, errStr := pool.callbackDispatch(ctx, msg)
|
result, errStr := pool.callbackDispatch(ctx, msg)
|
||||||
var resp Message
|
var resp Message
|
||||||
if errStr != "" {
|
if errStr != "" {
|
||||||
|
log.Printf("gobridge: handler %s error: %s", msg.Method, errStr)
|
||||||
resp = Message{ID: msg.ID, Type: TypeError, Error: errStr}
|
resp = Message{ID: msg.ID, Type: TypeError, Error: errStr}
|
||||||
} else {
|
} else {
|
||||||
data, _ := json.Marshal(result)
|
data, _ := json.Marshal(result)
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ import queue
|
|||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import traceback
|
||||||
from typing import Any, Callable, TypeVar
|
from typing import Any, Callable, TypeVar
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
@@ -346,6 +348,7 @@ def _dispatch(mux: _ConnMux, msg: dict):
|
|||||||
pass # ctx 取消,连接已被 Go 侧关闭,无需回写
|
pass # ctx 取消,连接已被 Go 侧关闭,无需回写
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
traceback.print_exc(file=sys.stderr)
|
||||||
mux.write({"id": msg_id, "type": "error", "error": str(e)})
|
mux.write({"id": msg_id, "type": "error", "error": str(e)})
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "gobridge"
|
name = "gobridge"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
description = "Python 端库,配合 Go 侧 gobridge 使用"
|
description = "Python 端库,配合 Go 侧 gobridge 使用"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user