JavaScript
js/no-empty-catch
A catch block never swallows an error silently; handle it, report it, or say in a comment why it is safe to ignore.
umiarkowanastatycznefe-javascript
Dlaczego
An empty catch {} or .catch(() => {}) turns a failure into nothing: the button stops working, the form never submits, and neither the user nor the error tracker hears about it. Debugging starts from "it does nothing".
Poprawka
Show the user a recoverable state (an error message with a retry), report the error to your logger, or rethrow it with context (throw new Error('Saving failed', { cause: err })). If ignoring it is correct (an optional feature that may be missing), write a comment in the block that says why.
Przykłady
// bad
try { await save(form) } catch {}
// good
try { await save(form) } catch (err) { showError('Could not save. Try again.'); report(err) }
try { localStorage.setItem('seen', '1') } catch { /* storage may be disabled; the banner just shows again */ }Źródła
Fakty
- Identyfikator
js/no-empty-catch- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
jsxhtmlvuesvelteastro- Uczy jej skill
fe-javascriptJavaScript in the browser- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain js/no-empty-catch