$ loading_
提供 TypeScript、Python 与 Go 的健壮错误处理模式与用户提示策略
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "error-handling" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/skills/error-handling/SKILL.md 2. 保存为 ~/.claude/skills/error-handling/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为 TypeScript、Python 和 Go 项目设计一套统一的错误处理规范,涵盖错误分类、typed errors、自定义异常、日志字段、用户可见报错文案,以及哪些错误应重试、降级或直接失败。
一份可落地的跨语言错误处理规范,包含分类原则、代码模式和用户提示建议。
我有一个会调用第三方支付接口的服务,请给出 TypeScript 或 Go 的错误处理方案,包含超时、重试退避、熔断器、幂等处理、监控告警,以及如何避免把底层错误直接暴露给用户。
一套面向生产环境的 API 容错方案,说明如何处理外部依赖失败并保护用户体验。
请帮我为前端应用设计错误边界与用户提示文案策略,区分网络错误、权限错误、表单校验错误和系统异常,并给出开发者日志记录内容与用户可操作的下一步建议。
一套前端错误边界与提示文案方案,兼顾技术可观测性和用户可理解性。
Consistent, robust error handling patterns for production applications.
catch block must either handle, re-throw, or log// Define an error hierarchy for your domain
export class AppError extends Error {
constructor(
message: string,
public readonly code: string,
public readonly statusCode: number = 500,
public readonly details?: unknown,
) {
super(message)
this.name = this.constructor.name
// Maintain correct prototype chain in transpiled ES5 JavaScript.
// Required for `instanceof` checks (e.g., `error instanceof NotFoundError`)
// to work correctly when extending the built-in Error class.
Object.setPrototypeOf(this, new.target.prototype)
}
}
export class NotFoundError extends AppError {
constructor(resource: string, id: string) {
super(`${resource} not found: ${id}`, 'NOT_FOUND', 404)
}
}
export class ValidationError extends AppError {
constructor(message: string, details: { field: string; message: string }[]) {
super(message, 'VALIDATION_ERROR', 422, details)
}
}
export class UnauthorizedError extends AppError {
constructor(reason = 'Authentication required') {
super(reason, 'UNAUTHORIZED', 401)
}
}
export class RateLimitError extends AppError {
constructor(public readonly retryAfterMs: number) {
super('Rate limit exceeded', 'RATE_LIMITED', 429)
}
}
For operations where failure is expected and common (parsing, external calls):
type Result<T, E = AppError> =
| { ok: true; value: T }
| { ok: false; error: E }
function ok<T>(value: T): Result<T> {
return { ok: true, value }
}
function err<E>(error: E): Result<never, E> {
return { ok: false, error }
}
// Usage
async function fetchUser(id: string): Promise<Result<User>> {
try {
const user = await db.users.findUnique({ where: { id } })
if (!user) return err(new NotFoundError('User', id))
return ok(user)
} catch (e) {
return err(new AppError('Database error', 'DB_ERROR'))
}
}
const result = await fetchUser('abc-123')
if (!result.ok) {
// TypeScript knows result.error here
logger.error('Failed to fetch user', { error: result.error })
return
}
// TypeScript knows result.value here
console.log(result.value.email)
import { NextRequest, NextResponse } from 'next/server'
function handleApiError(error: unknown): NextResponse {
// Known application error
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
code: error.code,
message: error.message,
...(error.details ? { details: error.details } : {}),
},
},
{ status: error.statusCode },
)
}
// Zod validation error
if (error instanceof z.ZodError) {
return NextResponse.json(
{
error: {
code: 'VALIDATION_ERROR',
message: 'Request validation failed',
details: error.issues.map(i => ({
field: i.path.join('.'),
message: i.message,
})),
},
},
…
召集四方视角进行结构化分歧讨论,辅助复杂决策与取舍判断。
自动生成测试场景并分析代理执行过程,量化技能与规则遵循率。
帮助用户在代码仓库中识别可远程利用、具备漏洞赏金价值的安全问题。
快速查询基因组数据库并完成序列检索、富集分析与可复现生信记录
用于把现有可用功能改成新行为,并同步更新测试、实现与提交把关。
在部署前校验路由器与交换机配置,提前发现安全与连通性风险。
提供地道 Go 语言模式与最佳实践,帮助构建健壮高效且易维护的应用
帮助开发者排查 VS Code 遥测中的未处理错误并定位根因。
帮助开发者掌握地道 Rust 模式、所有权、并发与错误处理实践
帮助开发者提取并核对 React 错误信息与错误码映射,排查未知错误码警告。
快速修复代码格式、Lint与常见错误,帮助提交前顺利通过 CI 检查
通过四个示例工具演示 MCP 服务的参数设计、结构化输出与错误处理