Thrown Errors within a query onSuccess fail silently
I have been working with https://github.com/OrJDev/solid-trpc. More specifically the SSR branch that makes use of
@adeora/solid-query
An issue I am running into or seeing is that the onSuccess
will silently fail if you happened to throw something inside:
Is this to be expected? One could put a try catch inside the onSuccess
. However the lack of logging of the throw or just in general at least doesn't feel correct?14 Replies
stormy-gold•3y ago
Not expected behavior! I’ll take a look at this.
Thanks for bringing it up ❤️
ambitious-aquaOP•3y ago
All good. Shout if you need anything. Been chatting a lot to OrJDev and figuring out these things. If you have stuff you want contribs to lemme know as well.
Also doc's or whatever.
plain-purple•3y ago
it's a query-core thing imo, not solid related. It's been discussed on GitHub before. We can't put the query in error state because callbacks run for each observer. What else should we do?
ambitious-aquaOP•3y ago
I see I see.
I do not know Tanstack Query well enough. When you say can't put it on error state does that mean you cannot pass the error to trigger
onError
?
Or what would be the implications of a onCatch
on something returned?
Last thought is I dont know if would be a bad design choice to have a try/catch around the entire useQuery
itself on my code and it just is able to catch something.
Once again all shots in the dark as I do not fully know how the inner workings in core are.plain-purple•3y ago
An error in onSuccess should be similar to an error in onClick or so. It should show up in the console but nothing else
ambitious-aquaOP•3y ago
My particular use case is I have some Zod stuff going on and essentially the error that would otherwise be thrown is just falling silent with no error. I think at very least should tell something is wrong if nothing else yeah.
plain-purple•3y ago
I feel like we just discussed this on GitHub 😅. Zod stuff should happen in the queryFn
ambitious-aquaOP•3y ago
If we take zod out the picture if there is some sort of throw. How should that be handled then?
stormy-gold•3y ago
We have a throwErrors option that can be set to true to throw errors from the queryn
ambitious-aquaOP•3y ago
Right I added that on the options and I am not seeing anything still.
plain-purple•3y ago
Some sort of throw in the onSuccess callback? Like I said, it should be logged (at least thats what i would expect the browser to do). I don't think we explicitly swallow them, but we also don't do anything with the error then.
throwErrors only handles errors from the queryFn
ambitious-aquaOP•3y ago
At the moment I am not seeing anything in the console with regards to the thrown error.
My main thing is just some visibility rather than it silently failing.
stormy-gold•3y ago
I think I know where the problem is. I’ll fix it tomorrow 😄
Okay I think I fixed it. So on the server we wont retry failed queries and if they error out they will throw to the nearest ErrorBoundary. One question I have for @TkDodo 🔮 is that should we print the error to the console or is that something we should let the user handle it? If we throw any errors that are caught by the ErrorBoundary solid-start doesn't log those errors to the server console by default
plain-purple•3y ago
if we print errors to the console, it should be behind an env check (development only)