Apply monorepo error handling patterns: Zod validation at boundaries, typed errors, early returns, and retry/backoff. Use when implementing error handling or input validation.
This skill consolidates error handling conventions across the monorepo.
Use when asked to:
any usage in catch blocksunknown in catch blocks and narrowimport { z } from "zod";
const Schema = z.object({
id: z.string().uuid(),
limit: z.number().int().positive().optional(),
});
const data = Schema.parse(input);
try {
await doWork();
} catch (error: unknown) {
if (error instanceof Error) {
console.error(error.message);
} else {
console.error("Unknown error", error);
}
}
const MAX_RETRIES = 3;
const BASE_DELAY_MS = 500;
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
try {
return await fetchData();
} catch (error: unknown) {
if (attempt === MAX_RETRIES) throw error;
await new Promise((resolve) =>
setTimeout(resolve, BASE_DELAY_MS * Math.pow(2, attempt)),
);
}
}