-
Notifications
You must be signed in to change notification settings - Fork 466
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
feat: Reduce caught exceptions in prettyDom
#1321
feat: Reduce caught exceptions in prettyDom
#1321
Conversation
…ghlight in pretty-dom. (These were often disruptive to developers who need to catch some other first-chance exception in the act as they may have to wade through these unexceptional occurrences on the way to get to their target first-chance exception.)
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f7ccda2:
|
Basically we reduce the number of caught exceptions? |
Indeed, unexceptional exceptions are a thorny problem in the JS ecosystem due to continued lack of sufficient IDE support for the kind of "just my code" debugger halting features that have existed for decades in other ecosystems. (This one in particular stings me at least once a year so I finally resolved to fix it at the source.) What are our next steps? |
prettyDom
} else { | ||
// If `colors` is not set, colorize if we're in node. | ||
return ( | ||
typeof process !== 'undefined' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This always needs to stay for environments that don't have process
e.g. browsers: #1323
What:
Added tests for
pretty-dom
to guard against potential behavioral regressions.Then optimized
shouldHighlight
inpretty-dom
to avoid unexceptional exceptions.Why:
When developers are using the debugging features to halt the debugger upon "caught exceptions" or "first-chance exceptions" as it may be called in some IDEs, unrelated test failures were disruptively stealing the developer's attention and contributing to premature test timeouts. These disruptions are generally unnecessary since the situation leading up to it can be easily avoided with refactoring.
The exception at hand is that
JSON.parse
throws when passed undefined and/or empty string values. It can be easily avoided because we know that it will throw, and we know the intent is to default the colorization selection.How:
Streamlined the logic in
shouldHighlight
to preserve the final result while including extra safety checks to avoid passing undefined/empty to JSON.parse.Checklist: