-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
The project currently suffers from deep nesting due to extensive use of chained .then() and .catch() blocks. This increases cognitive load and makes the code difficult to maintain and debug.
We aim to modernize the codebase by adopting async/await syntax, which allows for a flatter structure and more readable control flow.
Guidelines & Constraints
-
Error Handling: Avoid wrapping large blocks of code in a single generic
try/catch. Instead, use the "Hybrid Approach" by attaching.catch()directly to the awaitable promise when distinct error handling is required.- Bad: Wrapping 5 awaits in one try/catch where you lose context of which one failed.
- Good:
// Clear, flat error handling for specific steps const user = await getUser(id).catch(err => { throw new Error(`User fetch failed: ${err.message}`); }); const config = await getConfig(user).catch(err => { console.warn('Config failed, using defaults'); return DEFAULT_CONFIG; // possibly add a fallback here });
-
Parallelism: Be careful not to turn parallel operations into serial ones. If multiple promises were running concurrently (e.g., inside a
Promise.all), keep them that way.- Bad:
await a(); await b();(if they don't depend on each other) - Good:
await Promise.all([a(), b()]);
- Bad:
Acceptance Criteria
- Nesting depth is significantly reduced.
- Logic remains exactly the same (no functional changes).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels