question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor showModal to avoid having catch everywhere

See original GitHub issue

(follow up to this conversation)

https://github.com/getredash/redash/blob/2755e1275af400b9bca167602d33cfc9b8e52418/client/app/components/tags-control/TagsControl.jsx#L27-L30

@arikfr:

Coudln’t we handle this in showModal instead of having to add this everywhere?

@kravets-levko

Sadly, no After .catch() handler promise will go to next .then() handler, so if we catch that promises inside of dialog wrapper - the caller’s .catch() will not be called. It actually is not a problem, but browser will show unhandled rejection errors in console. We can either:

  1. don’t catch that promises and ignore errors in console;
  2. always add empty catch handler like I did here;
  3. replace browser’s Promise with something else that does not trigger unhandled rejection errors (e.g. “bluebird”) - prior to this PR we used Angular’s $q for this purpose;
  4. change a way we handle dialog’s close/dismiss events (for me current flow looks fine, but that annoying unhandled rejections…)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arikfrcommented, Jan 20, 2020

I don’t think the last suggestion is a good one. There just shouldn’t be an error when there isn’t one 😃

0reactions
arikfrcommented, Jan 20, 2020

We could avoid using promises here and just pass a callback for dialog closed and another (optional) for dialog cancelled. This way handler stays the same and we don’t have to abuse a promise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Advice on how to refactor a nested try/catch block inside a ...
The best way to avoid nesting is to make it in another function catch (Exception ex) { log.Error("blah blah", ex); FUNCTION_NAME() } private ......
Read more >
Weekly Digest (20 January, 2020 - 27 January, 2020) · Issue #4591 ...
#4566 Refactor showModal to avoid having catch everywhere, by arikfr #4565 Change visualizations import to be static, by arikfr ...
Read more >
How to re-write the code sample without try/catch block
Try-catch is best used in parts of your code when you think mistakes will occur that are out of your control for whatever...
Read more >
window.showModalDialog: What It is and Why You Should ...
When modal.html loads it will assign a value of 'foo' to window.returnValue and close itself via window.close() . The opening window (page.html) ...
Read more >
How to avoid try/catch statements nesting/chaining in ...
You are writing try/catch blocks everywhere to prevent errors that crash your app. Sometimes overly because: You want to standardize your errors management....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found