-
-
Notifications
You must be signed in to change notification settings - Fork 284
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
Proposal: throwOnError should be default behavior #885
Comments
Fully agree, the proposal for setting this as default or as an option on |
Actually just came to create this issue, then saw it here. Storage doesn't even have this as option yet supabase/storage-js#150. It'd be a breaking change to make this default, so this should just be an option when creating a client. Just Plus, if this feature is enabled globally, any call should automatically return Many new Supabase users make the mistake of not handling errors from the sdk correctly, and end up wasting time figuring out issues because of that. Giving a |
Completely agree @ConProgramming. Thanks for the suggestions! |
Alternatively, let us set import { createClient } from '@supabase/supabase-js'
export const createSupabase = async () => {
return createClient('https://xyzcompany.supabase.co', 'public-anon-key', {
throwOnErrors: true
})
} This, along with a fix for #801, would cut out loads of boilerplate. @kiwicopple @w3b6x9 @filipecabaco would you accept a PR for this? |
I wholeheartedly support this proposal. I would go so far as to say that going with the result pattern by default was a bold design choice but also a highly questionable one. Throwing on errors should be the default in any library. Returning result objects is useful in certain scenarios but should be implemented in the application instead of in a library. For our project it is cumbersome to integrate with supabase for the reasons mentioned in this thread. Downsides of the Result pattern:
There is nothin wrong with having an option for using result objects instead of standard error handling, but it should be opt-in and not the default. I'd like to ask you to at least consider changing this in the next major release. |
The first step would be to get The next step, making it the default, is a breaking change - so it needs more discussion. Either way, step 1 seems like good progress so that we can have a |
@kiwicopple have you seen the PR I opened? |
Any update on this one? |
Any update on this? |
Same here, this would reduce boilerplate code a lot in my project |
Bumping this aswell, I've also noticed that when chaining |
Bug report
Describe the bug
Admittedly this is not a bug, but i wanted this issue to end up in the
supabase-js
repo as that is where the decision would need to be made.As a new user of the
supabase-js
library, i was caught off guard by the API not throwing errors by default. Instead you need to remember to invokethrowOnError()
after every query. This change was previously made and discussed here: #32, and it seems others share my same concern.This is (IMO) an unusual behavior for an API where errors are silent by default.
.update()
mutations that fail can easily go unnoticed for example.Other popular libraries i use on a regular basis such as Prisma, Zod, etc. instead throw by default, and you either have to catch the error, or opt into the API that doesn't throw and returns an error object (see Zod docs for example).
cc @n-sviridenko, @rienheuver
The text was updated successfully, but these errors were encountered: