home / skills / willsigmon / sigstack / error-handling-auditor

error-handling-auditor skill

/plugins/app-dev/skills/error-handling-auditor

This skill audits TypeScript error handling to replace unsafe patterns with safe do-catch, logging, and fallbacks.

npx playbooks add skill willsigmon/sigstack --skill error-handling-auditor

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
779 B
---
name: Error Handling Auditor
description: Find and fix unsafe error handling in Leavn - try! force unwraps, empty catch blocks, silent try? failures
allowed-tools: Read, Edit, Grep
---

# Error Handling Auditor

Fix unsafe error handling:

1. **Find try! force unwraps**: Replace with do-catch + fallback
2. **Find empty catch {}**: Add `AppLog.error("Context: \(error)")`
3. **Find silent try?**: Add logging for important failures

Patterns:
```swift
// Fix try!
do {
    result = try riskyOperation()
} catch {
    AppLog.error("Operation failed: \(error)")
    result = fallbackValue
}

// Fix empty catch
} catch {
    AppLog.error("Failed to save: \(error)", category: .persistence)
}
```

Use when: Crash risks, silent failures, debugging issues, error handling audit

Overview

This skill audits code for unsafe error handling patterns and produces concrete fixes to reduce crashes and silent failures. It targets common anti-patterns such as forced unwraps, empty catch blocks, and silent try? calls, and recommends logging and fallback strategies. The result is safer, more debuggable code and fewer production surprises.

How this skill works

The auditor scans the codebase for known unsafe patterns (force unwraps, empty catch blocks, silent try? expressions). For each finding it suggests a safe replacement: do-catch with logging, explicit fallbacks, or adding contextual error logs. It can produce example code snippets and patch suggestions developers can apply manually or integrate into automated code review workflows.

When to use it

  • Before release to reduce crash risk from force unwraps
  • During security or reliability audits to find silent failures
  • When debugging elusive runtime errors with no logged context
  • As part of CI to catch new unsafe error handling patterns
  • When onboarding to ensure consistent error-handling practices

Best practices

  • Replace force unwraps with do-catch and a well-defined fallback value
  • Never leave catch blocks empty — always log error context and category
  • Avoid silent try? for important operations; log failures at appropriate level
  • Include contextual metadata (operation, file, category) in logs
  • Prefer explicit propagation or handling over swallowing errors

Example use cases

  • Convert a try! call that crashes in edge cases to a do-catch with fallback
  • Replace empty catch {} in persistence code with AppLog.error including category
  • Find try? usages that hide failures and add error logging for critical flows
  • Run as part of a pre-merge check to flag unsafe patterns to reviewers
  • Create a patch set that standardizes error handling across a module

FAQ

Will the auditor automatically change my code?

It produces suggested fixes and example snippets; integration for automatic patching is optional and must be enabled in your workflow.

Does it enforce a specific logging framework?

No. Examples use generic logging calls; you can adapt suggestions to your project's logging API and categories.