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.

Slate throws exceptions too liberally in relation to selection failures

See original GitHub issue

Hello,

I would like to start a discussion about error handling in Slate which I think is too strict as Errors are often thrown for things that could just as easily be ignored or replaced by a warning. These are in functions like toDOMPoint or toSlateRange when Slate is trying to do things like map a HTMLElement to a Node but cannot because there is no direct mapping (the HTMLElement is created indirectly by a Slate Node). In many cases Slate will throw an Error that will take down the whole page. I understand that various attributes can be applied to have Slate ignore certain regions of the editor but I’ve still found it a bit of a fight and I really don’t understand why Slate can’t just return early in cases where no DOM-to-Slate mapping exists. In fact, I have forked Slate and disabled these Errors (here and here) and made Slate return early and while this fork is a WIP, I can tell you that my app is much better for it - it’s less work for me and I will still find problems where things aren’t wired-up correctly and I no longer have anxiety of deploying to production and worrying about the WSOD when the user’s only crime was clicking on an empty <div/> (I know prod apps should have error handling but again it feels like I am having to handle more errors than is really necessary).

Some ideas:

  • As above, log a warning like React does when in development mode and only use Error when it is absolutely necessary (cannot be recovered/ignored).
  • Maybe Slate could add a onError callback to its API for users to learn about errors

Thoughts?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:57
  • Comments:11

github_iconTop GitHub Comments

27reactions
skogsmaskincommented, Apr 28, 2020

So far the only error that have been really problematic for me is this one (Cannot resolve a DOM point from Slate point):

Tracked in own issue here: https://github.com/ianstormtaylor/slate/issues/3575 (my comment here https://github.com/ianstormtaylor/slate/issues/3575#issuecomment-620568898)

It makes collaborative editing near impossible, because as far as I can tell, there is no way we are able to adjust the selection when a new value is coming in through props before slate-react tries to naively restore the current user selection to a potential invalid DOM-range.

16reactions
mpkellycommented, May 6, 2020

Hi @CameronAckermanSEL, I use componentDidCatch in production as it is necessary whether using Slate or not. However, it feels like Slate is the source of too many errors and that’s the key point. There is also the development experience when first getting started to consider, too - here people might not have proper error handling in place and have to constantly restart/refresh/whatever due to errors for things they probably don’t even care about.

Slate seems to think it has to do something based on every interaction with the editor otherwise there is a bug but I don’t think this is right. I guess raising errors was just the easiest approach for the library devs when trying to get 0.50 ready but I don’t think this is the best longterm approach for the library consumers who should ideally decide what is critical and what is not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Throw Exceptions (The Java™ Tutorials > Essential ...
This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment.
Read more >
The Rules of The Game | Bolder Advocacy
Section 501(c)(3) explicitly provides federal tax exemption to a charitable organization so long as it “does not participate in, or intervene in (including...
Read more >
Neutral vs. Conservative: The Eternal Struggle
The neutral gatekeeper institutions lean very liberal, though with a minority of conservative elites who are good at keeping their heads ...
Read more >
CRFM Benchmarking
Plaintiff misunderstands the special relationship exception to the economic ... Defendant waived any objection to the trial information by failing to raise ...
Read more >
Whiteness and the Historians' Imagination - JSTOR
whites' race and racial identity and the very construction of race itself. ... racism, the focus of study" throws into "sharp relief" the...
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