Async/await used consistently
Why it matters
Mixing .then() chains and async/await in the same codebase — or in the same function — creates inconsistent error propagation: .then() chains require .catch() while async/await uses try/catch, and mixing them means some rejections are caught by one mechanism and some by the other. ISO 25010:2011 §6.5.2 classifies this as a maintainability defect. Nested .then() chains also re-introduce the callback-pyramid problem that async/await was designed to solve, making control flow harder to read and independent async operations sequential when they could run in parallel.
Severity rationale
Low because mixed async styles do not cause immediate failures but produce inconsistent error handling that leads to unhandled rejections and makes the control flow significantly harder to read and maintain.
Remediation
Standardize on async/await throughout. Use Promise.all() for genuinely independent async operations — never await them sequentially when they don't depend on each other's results.
// Bad: nested .then() chains, mixed with async
async function loadUserData(id: string) {
return fetchUser(id)
.then((user) => fetchUserPosts(user.id)
.then((posts) => ({ user, posts })))
.catch((err) => console.error(err))
}
// Good: consistent async/await
async function loadUserData(id: string) {
try {
const user = await fetchUser(id)
const posts = await fetchUserPosts(user.id)
return { user, posts }
} catch (err) {
logger.error('Failed to load user data', err)
throw err
}
}
// Good: parallel operations with Promise.all
async function loadDashboard(userId: string) {
const [user, posts] = await Promise.all([
fetchUser(userId),
fetchUserPosts(userId),
])
return { user, posts }
}
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 Code Quality Essentials Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · maintainability.analysability — Maintainability — Analysability
Taxons
History
- 2026-04-18·v1.0.0·Initial import from code-quality-essentials·automated