-
-
Notifications
You must be signed in to change notification settings - Fork 924
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
Cast string into error while handling errors #1530
Conversation
|
This is good change probably. I did the casting mostly for undefined/null cases. I'm not sure it is expected if you throw a string to not get a string back but this does make things more homogenous. In any case this will require a more significant release than a patch to merge it. |
0e5d944
to
cf2ba61
Compare
Pull Request Test Coverage Report for Build 4107676088
💛 - Coveralls |
Throwing anything other than Error is considered an anti-pattern as it does not contain a stack trace (not possible to track it down). I agree that this change may cause breaking changes, however I believe it will point out existing issues rather than create them. But sure, let's leave it for bigger release :) |
I have also strongly typed |
@ryansolid also a question. Maybe we should only cast error in case we are passing it to onError hooks? function handleError(err: unknown): void {
const fns = ERROR && lookup(Owner, ERROR);
if (!fns) throw error;
const error = castError(err);
for (const f of fns) f(error);
} and in case they are not handled, we should throw them they way they are? This way we can fully control its type, without breaking change, and without enforcing the cast. |
I needed it for resources as well. That was actually where a lot of issues were happening. Especially how it affected SSR and communicating across the wire. |
Re-reading. This is a good idea. |
* Fix castError * Strongly type onError --------- Co-authored-by: Ryan Carniato <ryansolid@gmail.com>
Summary
I am proposing to cast strings into errors, to make sure
castError
will always return the error. This will unify the behaviur and simplify errors handling by users. Also the original error, whether string or object, will be now attached ascause
of the error.How did you test this change?
pnpm test