← 返回 Skills 市场
laimiaohua

GI Error Handling

作者 laimiaohua · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
163
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install gi-error-handling
功能描述
Handle errors and logging following project conventions. Use when implementing exception handling, adding logs, or when the user asks for error handling patt...
使用说明 (SKILL.md)

Error Handling 错误处理与日志

按项目规范实现错误处理与日志记录。适用于 API 异常、业务错误、日志打点,便于排查问题。

何时使用

  • 用户请求「加错误处理」「加日志」「异常处理」
  • 实现 API 的异常返回
  • 排查问题时需要定位错误来源

异常处理

1. 业务异常

from tkms.exception.api import ApiException

# 抛出业务异常,会返回给前端
raise ApiException(code=400, message="用户不存在")
raise ApiException(code=401, message="未登录")
raise ApiException(code=403, message="无权限")
raise ApiException(code=404, message="资源不存在")
raise ApiException(code=500, message="服务器内部错误")
  • code:HTTP 状态码或业务错误码
  • message:返回给前端的错误信息,避免暴露内部细节

2. 参数校验

if not user_id:
    raise ApiException(code=400, message="用户ID不能为空")

if page \x3C 1:
    raise ApiException(code=400, message="页码必须大于0")

3. 资源不存在

user = await self.user_dao.get_by_id(user_id)
if not user:
    raise ApiException(code=404, message="用户不存在")

4. 捕获并转换

try:
    result = await external_api.call()
except ConnectionError as e:
    raise ApiException(code=502, message="服务暂时不可用")
except Exception as e:
    # 记录详细日志,对外返回通用信息
    logger.exception("调用外部服务失败")
    raise ApiException(code=500, message="操作失败,请稍后重试")

日志规范

1. 打点位置

  • 接口入口:logger.info("接口名 入参")
  • 关键业务节点:logger.info("步骤 结果")
  • 异常:logger.exception("异常描述")logger.error("...")

2. 日志内容

  • 不输出密码、Token、完整卡号等敏感信息
  • 包含关键上下文:user_id、request_id、操作类型
  • 异常时记录堆栈便于排查

3. 示例

import logging
logger = logging.getLogger(__name__)

# 入口
logger.info("get_user_list", extra={"user_id": user_id, "page": page})

# 业务节点
logger.info("查询完成", extra={"count": len(rows)})

# 异常
logger.exception("数据库查询失败", extra={"sql": sql_safe})

统一响应格式

成功:

{"code": 0, "message": "success", "data": {...}}

失败(由 ApiException 触发):

{"code": 400, "message": "用户不存在"}

前端错误处理

  • 根据 code 区分:401 跳登录、403 提示无权限、其他展示 message
  • 网络错误:统一提示「网络异常,请稍后重试」
安全使用建议
This is an instruction-only helper that outlines how to raise ApiException and structure logs and responses. It's internally consistent and low-risk. Before using, verify the examples match your project's libraries (the examples reference a project-specific 'tkms' module and async usage); adapt names and imports to your codebase. No credentials or installs are requested, so risk is limited to following the coding conventions provided.
功能分析
Type: OpenClaw Skill Name: gi-error-handling Version: 1.0.0 The skill bundle provides standard coding guidelines and examples for error handling and logging within a specific project framework (tkms). It promotes security best practices by explicitly instructing the agent not to log sensitive information like passwords or tokens and to avoid exposing internal system details in API responses (SKILL.md).
能力评估
Purpose & Capability
The name and description match the SKILL.md content: examples and conventions for ApiException handling and logging. Nothing requested (no env vars, no binaries, no installs) is inconsistent with this purpose.
Instruction Scope
SKILL.md stays on-topic (raising ApiException, logging, response format, front-end handling). One minor note: examples import from a project-specific module 'tkms.exception.api' and use async patterns—these are examples tied to a particular codebase and assume those libraries/conventions exist in the target project. The instructions do not ask to read unrelated files, environment variables, or transmit data externally.
Install Mechanism
No install spec (instruction-only). Nothing is downloaded or written to disk; this is the lowest-risk option.
Credentials
No environment variables, credentials, or config paths are requested. The guidance does not attempt to collect secrets or require unrelated service tokens.
Persistence & Privilege
always is false and the skill is user-invocable. It does not request permanent/system-level privileges or attempt to modify other skills' configurations.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install gi-error-handling
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /gi-error-handling 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release. Gravitech Innovations.
元数据
Slug gi-error-handling
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

GI Error Handling 是什么?

Handle errors and logging following project conventions. Use when implementing exception handling, adding logs, or when the user asks for error handling patt... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 163 次。

如何安装 GI Error Handling?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install gi-error-handling」即可一键安装,无需额外配置。

GI Error Handling 是免费的吗?

是的,GI Error Handling 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

GI Error Handling 支持哪些平台?

GI Error Handling 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 GI Error Handling?

由 laimiaohua(@laimiaohua)开发并维护,当前版本 v1.0.0。

💬 留言讨论