Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable linting rules for non-awaited Promises inside of try / catch #2154

Closed
bmingles opened this issue Jul 17, 2024 · 0 comments · Fixed by #2157
Closed

Enable linting rules for non-awaited Promises inside of try / catch #2154

bmingles opened this issue Jul 17, 2024 · 0 comments · Fixed by #2157
Assignees
Labels
enhancement New feature or request triage Issue requires triage

Comments

@bmingles
Copy link
Contributor

Returning promises from a try block without awaiting won't actually catch errors associated with the rejection of said Promise.

async function throwsError() {
  throw "Some error that was thrown.";
}

async function main() {
  const appEl = document.getElementById("app");

  try {
    await throwsError();
  } catch (err) {
    // This works since the rejected Promise is awaited
    appEl.innerHTML = "Error A";
  }

  try {
    throwsError();
  } catch (err) {
    // This won't catch since the Promise is resolved after the try / catch has been run
    appEl.innerHTML = "Error B";
  }
}

main();

There is an eslint rule that can guard against this issue:
https://typescript-eslint.io/rules/return-await/

// Note: you must disable the base rule as it can report incorrect errors
'no-return-await': 'off',
'@typescript-eslint/return-await': 'error',

We should enable it, and fix any offending code. Running this on web-client-ui, I currently see 2 offending places:

packages/iris-grid/src/IrisGridTableModelTemplate.ts valuesTable
image

packages/utils/src/ClipboardUtils.ts copyToClipboard
image

@bmingles bmingles added enhancement New feature or request triage Issue requires triage labels Jul 17, 2024
@bmingles bmingles self-assigned this Jul 17, 2024
bmingles added a commit to bmingles/web-client-ui that referenced this issue Jul 17, 2024
bmingles added a commit to bmingles/web-client-ui that referenced this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage Issue requires triage
Projects
None yet
1 participant