Skip to content
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

Type PostgrestError is not assignable to class PostgrestError #561

Closed
2 tasks done
ghost opened this issue Oct 18, 2024 · 3 comments
Closed
2 tasks done

Type PostgrestError is not assignable to class PostgrestError #561

ghost opened this issue Oct 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Oct 18, 2024

As we and probably most use postgrest-js through supabase-js, I also opened a bug report there: supabase/supabase-js#1287

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

With the latest release v2.45.5 when importing PostgrestError from supabase-js, the PostgrestError class (https://github.com/supabase/postgrest-js/blob/master/src/PostgrestError.ts) is now imported instead of the PostgrestError type (https://github.com/supabase/postgrest-js/blob/master/src/types.ts) which are not compatible:

Type PostgrestError is not assignable to type PostgrestError.

This change was introduced with this pull request: #555

To reproduce

Write a generic function with a PostgrestError object as a parameter:

import { PostgrestError } from '@supabase/supabase-js'

export function handlePostgrestError(error: PostgrestError) {
  // do stuff
}

Then try to use this function with an error object returned by, e.g., a Supabase query:

import { createClient } from '@supabase/supabase-js'

const supabase = createClient<Database>(
  import.meta.env.SUPABASE_URL,
  import.meta.env.SUPABASE_KEY,
)

function loadData(someId: string) {
  const { data, error } = await supabaseAdmin
    .from('some_table')
    .select('some_column')
    .eq('id', someId)
    .single()

  if (error) {
    handlePostgrestError(error)
    return
  }

  ...
}

Expected behavior

Type-check is successful

System information

  • Version of supabase-js: v2.45.5
@ghost
Copy link
Author

ghost commented Oct 18, 2024

At first glance I could not find a reason why the type PostgrestError is necessary and whether the class PostgrestError can be used in place of type PostgrestError: #562

@maximilian-hammerl
Copy link

My PR #562 was merged, and the changes have already been released in v1.16.3
Thanks @soedirgo for the quick response!

I opened a PR to update the postgrest-js dependency of supabase-js: supabase/supabase-js#1289

@soedirgo
Copy link
Member

Thanks for the PR @maximilian-hammerl! I’ve merged the supabase-js PR so the new release should be available soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants