Skillshub swift-error-handling
Standards for Throwing Functions, Result Type, and Never. Use when implementing Swift error throwing, Result<T,E>, or designing error hierarchies. (triggers: **/*.swift, throws, try, catch, Result, Error)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/swift-error-handling" ~/.claude/skills/comeonoliver-skillshub-swift-error-handling && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/swift-error-handling/SKILL.mdsource content
Swift Error Handling
Priority: P0
Implementation Guidelines
Throwing Functions
- Propagate Errors: Use
for recoverable errors andthrows
for modern concurrency.async throws - Do-Catch: Handle errors close to source with specific catch clauses for each error type. Catch-all
should be the last resort.catch - Error Types: Define custom errors as
conforming to Error (e.g.,enum
) for user-facing descriptions.enum NetworkError: Error { case connectionLost } - Optional Try: Use
only for non-critical errors.try?
Result Type
- Async Alternatives: Use throws for synchronous code. Use Result for callbacks and non-async deferred error states.
- Transformations: Use
,.map()
for functional composition..flatMap() - Conversion: Use
to convert.get()
to throwing for use inResult
.try-catch
Never Type & Preconditions
- Fatalisms: Use
return type only for unrecoverable crash scenarios or to indicate unreachable code. Never for expected errors.Never - Preconditions: Use
,precondition()
, andassert()
for programmer errors. UsefatalError()
for debug-only checks.assertionFailure()
Anti-Patterns
- No try!: Use try? or do-catch.
- No try? without nil check: Handle or log.
- No Error(message): Use typed errors.