Skip to content

no-unsafe-finally

Reports return, throw, and a break or continue that leaves the finally block, written in a finally. A break or continue of a loop inside the block, and a return in a function declared in the block, are not reported.

A jump out of finally replaces how the try ended: a return there discards the value returned by the try and swallows an exception that was being thrown, so errors disappear without a trace.

To fix, move the jump out of finally (after the try statement), or handle the error in a catch.

Reported
function f() { try { a(); } finally { return 1; } }
function g() { try { a(); } finally { throw e; } }
function h() { for (;;) { try { a(); } finally { break; } } }
function i() { try { a(); } finally { for (;;) { break; } } }
function j() { try { a(); } finally { function k() { return 1; } } }
function l() { l: try { a(); } finally { break l; } }
function m() { try { a(); } finally { m: { break m; } } }
...
js:
lint:
rules:
no-unsafe-finally: warn # off, warn (default), error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-unsafe-finally in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-unsafe-finally full