Skip to content

[Priority: Med] [Enhancement] 引入中心化错误映射机制 (ErrorTranslator) #274

@liujuanjuan1984

Description

@liujuanjuan1984

🔍 发现的问题 / 原始需求描述

目前错误转换逻辑散落在 upstream_errors.pyexecutor.pyjsonrpc/application.py 中,导致不同报错链路(上游 API、A2A 协议校验、沙箱策略)的错误返回行为缺乏统一标准。

🛠️ 详细实施方案

  • 涉及文件: src/opencode_a2a_server/execution/errors.py
  • 核心逻辑:
    1. 定义 ErrorTranslator 类,将各类异常统一映射为 A2A 标准的 event_queue 失败事件或符合 A2A 规范的 JSON-RPC 错误码。
    2. 使用 Python 枚举定义标准错误类型,确保 type=METHOD_NOT_SUPPORTED 等字段在各处调用一致。
  • 伪代码:
    class ErrorTranslator:
        @staticmethod
        def to_a2a_event(exc: Exception) -> dict[str, Any]: ...
        
        @staticmethod
        def to_jsonrpc_error(exc: Exception) -> JsonRpcError: ...

🧪 回归测试建议

  • 使用不同的测试用例模拟 HTTP 500、404、权限不足等上游报错。
  • 验证返回的 A2A 事件格式(failed 状态)在各接口下完全对齐。

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:todoPlanned but not started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions