swift error handling
1
总安装量
0
周安装量
#49669
全站排名
安装命令
npx skills add https://github.com/hoangnguyen0403/agent-skills-standard --skill Swift Error Handling
Skill 文档
Swift Error Handling
Priority: P0
Implementation Guidelines
Throwing Functions
- Propagate Errors: Use
throwsfor recoverable errors. - Do-Catch: Handle errors close to source with specific catch blocks.
- Error Types: Define custom errors as enums conforming to
Error.
Result Type
- Async Alternatives: Use
Result<Success, Failure>for callback-based APIs. - Transformations: Use
.map(),.flatMap()for functional composition. - Conversion: Use
.get()to convertResultto throwing.
Never Type
- Fatalisms: Use
Neverreturn type for functions that never return. - Preconditions:
fatalError(),preconditionFailure()for programmer errors.
Anti-Patterns
- Force Try:
**No try!**: Use try? or do-catch. - Silent Failures:
**No try? without nil check**: Handle or log. - String Errors:
**No Error(message)**: Use typed errors.