From db71a904e0c5a1eb812a36b157e13c47865b52a7 Mon Sep 17 00:00:00 2001 From: what Date: Wed, 20 May 2026 19:30:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Python 侧 _dispatch 异常时输出完整堆栈到 stderr - Go 侧 handler 返回 error 时打印日志 - 升级 Python 包版本至 0.1.4 --- client.go | 2 ++ python/gobridge/__init__.py | 3 +++ python/pyproject.toml | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) 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"