Async error handling is consistent across the codebase
Why it matters
A codebase where some async functions use try/catch, others use .catch(), some use a shared wrapper, and some have no error handling at all makes every error handling review a full context-reload. CWE-755 (Improper Handling of Exceptional Conditions) applies when inconsistency means individual developers add error handling differently, creating gaps that are hard to detect in review. ISO 25010 maintainability.consistency classifies ad hoc error handling as a direct maintainability defect. Practically, a boilerplate-heavy pattern copy-pasted across 15 server actions means adding cross-cutting behavior — like logging or monitoring calls — requires editing every location individually rather than once in a shared utility.
Severity rationale
Low because inconsistent async error handling is a code quality and maintainability defect rather than an immediate security or reliability risk, but it degrades both over time.
Remediation
Create a shared tryCatch utility in src/lib/try-catch.ts and standardize server actions and API helpers on it.
// src/lib/try-catch.ts
export async function tryCatch<T>(
fn: () => Promise<T>
): Promise<[T, null] | [null, Error]> {
try {
const result = await fn()
return [result, null]
} catch (error) {
return [null, error instanceof Error ? error : new Error(String(error))]
}
}
// Usage in a server action:
const [user, error] = await tryCatch(() => db.users.findUnique({ where: { id } }))
if (error) { return { error: 'User not found' } }
Once a shared utility is in place, adding cross-cutting logging or monitoring to all async calls requires a single edit in one file rather than hunting across the codebase.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Error Handling Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-755 — Improper Handling of Exceptional Conditions
- iso-25010:2011 · maintainability.modifiability
Taxons
History
- 2026-04-18·v1.0.0·Initial import from saas-error-handling·automated