agentleFS
kelvinkosbabkelvinkosbab/KozBon/.claude/skills/swift-error-handling-pro/SKILL.md

swift-error-handling-pro

Skill5 starsChanged 11 days agoMITView on GitHub

Reviews Swift error handling for modern patterns including typed throws, Result vs throws, LocalizedError conformance, and async error propagation. Use when writing or reviewing Swift error types and throwing functions.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Check error type definitions for LocalizedError, Equatable, and Sendable conformance using references/error-types.md.

    line 14
  2. Very specific:

    Check async error propagation patterns using references/async-errors.md.

    line 17
  3. Distinctive:

    If doing a partial review, load only the relevant reference files.

    line 20
  4. Very specific:

    Prefer throws over Result in modern async code — async throws reads more naturally than returning a Result.

    line 26
  5. Very specific:

    Never use try! or try? to silence errors that could meaningfully be handled or surfaced.

    line 29
  6. Very specific:

    Avoid catch { } blocks that swallow the error — at minimum, log it.

    line 30
  7. Distinctive:

    Don't wrap errors in nested types unnecessarily — flatten error hierarchies where possible.

    line 31

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Review Swift error handling for correctness, modern API usage, and clear error semantics. Report only genuine problems - do not nitpick or invent issues.

Review process:

  1. Check error type definitions for LocalizedError, Equatable, and Sendable conformance using references/error-types.md.
  2. Evaluate whether typed throws (Swift 6.0+) would clarify the API using references/typed-throws.md.
  3. Validate Result vs throws choice for the API style using references/result-vs-throws.md.
  4. Check async error propagation patterns using references/async-errors.md.
  5. Flag swallowed errors (catch blocks that ignore errors silently).

If doing a partial review, load only the relevant reference files.

Core Instructions

  • Target Swift 6.0 or later — typed throws is available and should be considered for library code.
  • Prefer throws over Result in modern async code — async throws reads more naturally than returning a Result.
  • Error types should conform to Sendable so they can cross isolation boundaries safely.
  • Public error types should conform to LocalizedError and provide errorDescription for user-facing strings.
  • Never use try! or try? to silence errors that could meaningfully be handled or surfaced.
  • Avoid catch { } blocks that swallow the error — at minimum, log it.
  • Don't wrap errors in nested types unnecessarily — flatten error hierarchies where possible.

Output Format

Organize findings by file. For each issue:

  1. State the file and relevant line(s).
  2. Name the rule being violated.
  3. Show a brief before/after code fix.

Skip files with no issues. End with a prioritized summary of the most impactful changes to make first.

Example output:

Sources/Storage/FileStoreError.swift

Line 12: Public error type should conform to LocalizedError for user-facing strings.

// Before
public enum FileStoreError: Error {
    case readFailed
    case writeFailed
}

// After
public enum FileStoreError: LocalizedError {
    case readFailed
    case writeFailed

    public var errorDescription: String? {
        switch self {
        case .readFailed: "Failed to read from disk."
        case .writeFailed: "Failed to write to disk."
        }
    }
}

Line 34: Use typed throws for clearer API contract.

// Before
public func read() throws -> Data

// After
public func read() throws(FileStoreError) -> Data

Summary

  1. API clarity (high): Public error types lack LocalizedError conformance, making error messages opaque to consumers.
  2. Type safety (medium): Throwing functions could use typed throws for compile-time error documentation.

End of example.

References

  • references/error-types.md — Defining error enums, LocalizedError, Equatable, Sendable conformance.
  • references/typed-throws.md — Swift 6.0 typed throws syntax, when to use, performance benefits, migration.
  • references/result-vs-throws.md — When to use Result<T, E> vs throws, async considerations, callback APIs.
  • references/async-errors.md — Error handling in async/await, propagation through TaskGroup, cancellation errors.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.