-
Notifications
You must be signed in to change notification settings - Fork 0
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
Return errors instead of throwing them #3
Comments
Hi @peruibeloko, Thanks for raising this point about error handling! While I appreciate your perspective on exceptions as an anti-pattern, I see them as a valid tool in many scenarios, especially for handling truly exceptional situations (like runtime errors). That said, I acknowledge that returning errors can improve code clarity in certain cases. I'm not planning on making a wholesale change to the error handling right now, but I'm definitely open to exploring a hybrid approach in the future. This might involve returning errors for more predictable scenarios and reserving exceptions for truly unexpected issues. Would you be willing to share some specific examples from your experience where you've found returning errors to be a particularly effective approach? This would help me understand your use case better. |
Absolutely @Pinta365! Thanks for the attention :) My current use case is perhaps one of the most common: Issuing and verifying JWTs for Bearer Authentication. The suggestion stems from my current setup which relies on using the Since the signing keys are unique to each user (a possibly unfortunate design choice), I need to first verify the integrity of the JWT, before retrieving the user email from the Unsafely parsing the JWT to check for its integrity may be avoided in my specific case, but its nonetheless a pretty common thing to do (I suppose :P) in order to quickly reject any invalid requests, before attempting to fully verify the message, which might pose workload implications. All this really boils down to preference, as you said yourself, and could easily be circumvented by wrapping the exception handling inside an I'm also open to help implementing said 'mixed' approach, which reminds me of Carson Gross' take on APIs EDIT: I also just remembered that TypeScript currently does not infer exceptions types, which even though is listed on my original topic list, is an important point to make, as it requires both maintainers to explicitly declare all possible thrown exceptions on the JSDoc, and developers to explicitly import and use them in their own code, which can lead to worse code quality overall. |
Motivations:
try
/catch
logiccause
property of ErrorThe text was updated successfully, but these errors were encountered: