{"record":{"id":"47996938a6832732","repo":"oxc-project/oxc","slug":"prefer-await-to-then-catch-finally","errorCode":null,"errorMessage":"Prefer await to then()/catch()/finally()","messagePattern":"Prefer await to then\\(\\)/catch\\(\\)/finally\\(\\)","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/promise/prefer_await_to_then.rs","lineNumber":9,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nfn prefer_wait_to_then_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer await to then()/catch()/finally()\")\n        .with_help(\"Use `await` with `try`/`catch` instead of promise chaining for more readable and maintainable async code.\")\n        .with_label(span)\n}\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::is_promise_with_context,\n};\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct PreferAwaitToThen(PreferAwaitToThenConfig);\n\nimpl std::ops::Deref for PreferAwaitToThen {\n    type Target = PreferAwaitToThenConfig;\n\n    fn deref(&self) -> &Self::Target {","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/promise/prefer_await_to_then.rs#L1-L27","documentation":"Diagnostic from the oxlint rule `promise/prefer-await-to-then` (plugin `promise`, style category). It fires on every `.then()`, `.catch()`, or `.finally()` member call whose receiver the `is_promise_with_context` utility resolves as a promise. The rule takes no configuration: if it is enabled, all chaining syntax is flagged in favor of `async`/`await` with `try`/`catch`.","triggerScenarios":"Any `x.then(fn)`, `x.catch(fn)`, or `x.finally(fn)` in files covered by the rule; enabling the whole `promise` plugin or the `style` category in `.oxlintrc.json` turns this rule on.","commonSituations":"Enabling `promise` plugin presets wholesale in an oxlint config migration; mixed-style codebases where chains are intentional; teams that standardized on async/await and want chains gone.","solutions":["Rewrite the chain as an `async` function with `await` and `try`/`catch`","If the codebase intentionally uses chains, disable the rule: `\"promise/prefer-await-to-then\": \"off\"`","Scope the rule to new directories only (e.g. `src/modern/**`) via config overrides"],"exampleFix":"// before\ngetUser(id)\n  .then(render)\n  .catch(showError)\n  .finally(hideSpinner)\n\n// after\nasync function load(id) {\n  try {\n    const user = await getUser(id)\n    render(user)\n  } catch (err) {\n    showError(err)\n  } finally {\n    hideSpinner()\n  }\n}","handlingStrategy":"validation","validationCode":"npx oxlint --promise/prefer-await-to-then src/\n# chain-based codebase? turn it off in .oxlintrc.json:\n#   { \"rules\": { \"promise/prefer-await-to-then\": \"off\" } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one async style per codebase and encode it in the shared oxlint config","Check which rules the `promise` plugin preset enables before adopting it wholesale","Default to `async/await` + `try/catch/finally` in new code"],"tags":["promise","async","await","lint","code-style","oxlint"],"backgroundTag":"prefer-await-over-promise-chains","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}