Skip to content

Log And Rethrow Duplication (ARCH3166)

Key typescript.logging.log-and-rethrow · Severity warning · Category logging

Logging an exception and then rethrowing it in the same handler produces duplicate log entries when it is logged again higher up the stack. The same error appears repeatedly.

async function loadProfile(id: string): Promise<Profile> {
try {
return await repo.get(id);
} catch (err) {
logger.error("failed to load profile", { id, err });
throw err;
}
}
async function loadProfile(id: string): Promise<Profile> {
// the top-level boundary handler logs the error once
return await repo.get(id);
}

Either log or rethrow; log the exception once at a single central boundary handler.