← Back to Skills Marketplace
laimiaohua

GI Error Handling

by laimiaohua · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
163
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install gi-error-handling
Description
Handle errors and logging following project conventions. Use when implementing exception handling, adding logs, or when the user asks for error handling patt...
README (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
  • 网络错误:统一提示「网络异常,请稍后重试」
Usage Guidance
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.
Capability Analysis
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).
Capability Assessment
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.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install gi-error-handling
  3. After installation, invoke the skill by name or use /gi-error-handling
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release. Gravitech Innovations.
Metadata
Slug gi-error-handling
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is 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... It is an AI Agent Skill for Claude Code / OpenClaw, with 163 downloads so far.

How do I install GI Error Handling?

Run "/install gi-error-handling" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is GI Error Handling free?

Yes, GI Error Handling is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does GI Error Handling support?

GI Error Handling is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created GI Error Handling?

It is built and maintained by laimiaohua (@laimiaohua); the current version is v1.0.0.

💬 Comments