Skip to content
Sarj Code Standards

no-fat-try-blocks

Review try blocks exceeding the configured count of syntactically selected operations.

Why

A broad try block obscures which operation failed and encourages one catch clause to recover from unrelated errors.

Fix

Keep only the operations that share one recovery policy inside the try block and move other work outside it.

Examples

Before — flagged Review whether four selected operations share one recovery policy
src/load.ts
function f() {
try {
const a = one();
const b = two();
const c = three();
const d = four();
} catch (error) {
handle(error);
}
finish();
}
After — preferred Keep only operations with the same recovery policy in the try block
src/load.ts
function f() {
try {
const a = one();
const b = two();
const c = three();
} catch (error) {
handle(error);
}
const d = four();
finish();
}

Options

{
"additionalProperties": false,
"properties": {
"max": {
"description": "Maximum number of statements allowed in one try body.",
"minimum": 1,
"type": "integer"
}
},
"type": "object"
}