supabase / realtime-js

An isomorphic Javascript client for Supabase Realtime server.
https://supabase.com
MIT License
321 stars 56 forks source link

JSON parse error: SyntaxError: JSON Parse error: Unexpected character: d #277

Open evelant opened 8 months ago

evelant commented 8 months ago

Bug report

Describe the bug

supabase-js is logging JSON parse error: SyntaxError: JSON Parse error: Unexpected character: d with no stack and no further detail after successfully upserting a row to the database.

To Reproduce

   const { count, data, error } = await db
                        .from(table_name)
                        .upsert(snapshot as any, { ignoreDuplicates: false, onConflict: "id" })
                        .eq("id", id)
                        .select()
                        .single()

With the above upsert error is null but somewhere internal to supabase-js logs JSON parse error: SyntaxError: JSON Parse error: Unexpected character: d. If I comment out this upsert operation the spurious error log goes away.

Expected behavior

If there is an error supabase-js should return or throw it

Screenshots

N/A

System information

Additional context

evelant commented 8 months ago

Actually this appears to be coming from realtime. The following code:

export function listenToDbDocument<DocType extends { [key: string]: any }>(
    connection: SupabaseClientType,
    table_name: string,
    docId: string,
    onDocChange: (change: DbDocChangeType<DocType>) => void,
): () => void {
    log.log(`Listening to "${table_name}" for document "${docId}"`)

    connection
        .from(table_name)
        .select("*")
        .eq("id", docId)
        .single()
        .then(doc => {
            console.log(`got initial doc`)
        })

    const channel = connection
        .channel(docId)
        .on(
            "postgres_changes",
            { event: "UPDATE", schema: "public", table: table_name, filter: `id=eq.${docId}` },
            update => {
               console.log(`got change`)
            },
        )
        .subscribe()

    return channel.unsubscribe
}

On every change that comes in on the postgres_changes channel it logs JSON parse error: SyntaxError: JSON Parse error: Unexpected character: d just before the callback is run with the update. There are no errors, the update message is fine.

ddx-510 commented 3 months ago

Having similar issues here, have a strange LOG JSON parse error: SyntaxError: JSON Parse error: Unexpected end of input

I log all the payload is fine

ddx-510 commented 3 months ago

Having similar issues here, have a strange LOG JSON parse error: SyntaxError: JSON Parse error: Unexpected end of input

I log all the payload is fine

Hey, I eventually found out that the backend inserted a wrong type to a jsonb field in supabase. However, this does not trigger any error log cuz the payload is already inside and it is assumed to be the correct type.

So either avoid this in the backend or find some ways to raise this error in supabase js

Yeasirarafat53 commented 1 week ago

same as for me:

Error All course fetching data: [SyntaxError: JSON Parse error: Unexpected character: N]