- 在函数开头处理错误和边缘情况。
- 对错误条件使用提早返回,以避免深度嵌套的 if 语句。
- 将"快乐路径"(正常执行路径)放在函数末尾,以提高可读性。
- 避免不必要的 else 语句;改用 if-return 模式。
- 使用卫语句(guard clauses)尽早处理前置条件和无效状态。
- 实现适当的错误日志记录和用户友好的错误消息。
- 使用自定义错误类型或错误工厂以实现一致的错误处理。
Fastapi API Example Error Handling Priorities
Use when working with FastAPI — error handling, guard clauses, early return patterns
Fastapi API Example Error Handling Priorities by liaosw97 · 7d77248
npx skillmds@latest add liaosw97/fastapi-api-example-error-handling-priorities File contents
---name: fastapi-api-example-error-handling-prioritiesdescription: Use when working with FastAPI — error handling, guard clauses, early return patterns---- 在函数开头处理错误和边缘情况。 - 对错误条件使用提早返回,以避免深度嵌套的 if 语句。 - 将"快乐路径"(正常执行路径)放在函数末尾,以提高可读性。 - 避免不必要的 else 语句;改用 if-return 模式。 - 使用卫语句(guard clauses)尽早处理前置条件和无效状态。 - 实现适当的错误日志记录和用户友好的错误消息。 - 使用自定义错误类型或错误工厂以实现一致的错误处理。
liaosw97/awesome-rules-skills/tree/main/plugins/fastapi/skills/fastapi-api-example-error-handling-priorities commit 7d77248d58
Frequently asked questions
Run npx skillmds@latest add liaosw97/fastapi-api-example-error-handling-priorities in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Use when working with FastAPI — error handling, guard clauses, early return patterns It is listed under Integrations & APIs on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
liaosw97 (@liaosw97) published this skill. Their other Agent Skills are listed on their SkillMD profile.