diff --git a/client.go b/client.go index 808ddb4..1991466 100644 --- a/client.go +++ b/client.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "fmt" + "log" "net" "reflect" "sync" @@ -105,6 +106,7 @@ func readResult(ctx context.Context, conn net.Conn, pool Pool, write func(Messag result, errStr := pool.callbackDispatch(ctx, msg) var resp Message if errStr != "" { + log.Printf("gobridge: handler %s error: %s", msg.Method, errStr) resp = Message{ID: msg.ID, Type: TypeError, Error: errStr} } else { data, _ := json.Marshal(result) diff --git a/python/gobridge/__init__.py b/python/gobridge/__init__.py index 2b417c3..0a935fb 100644 --- a/python/gobridge/__init__.py +++ b/python/gobridge/__init__.py @@ -46,7 +46,9 @@ import queue import signal import socket import struct +import sys import threading +import traceback from typing import Any, Callable, TypeVar T = TypeVar("T") @@ -346,6 +348,7 @@ def _dispatch(mux: _ConnMux, msg: dict): pass # ctx 取消,连接已被 Go 侧关闭,无需回写 except Exception as e: + traceback.print_exc(file=sys.stderr) mux.write({"id": msg_id, "type": "error", "error": str(e)}) finally: diff --git a/python/pyproject.toml b/python/pyproject.toml index f9dc405..04da48f 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "gobridge" -version = "0.1.3" +version = "0.1.4" description = "Python 端库,配合 Go 侧 gobridge 使用" requires-python = ">=3.10"