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

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

Open
evelant opened this issue Feb 7, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@evelant
Copy link

evelant commented Feb 7, 2024

Bug report

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

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

  • OS: macOS
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: 2.39.3
  • Version of Node.js: N/A

Additional context

@evelant evelant added the bug Something isn't working label Feb 7, 2024
@evelant
Copy link
Author

evelant commented Feb 7, 2024

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.

@kangmingtay kangmingtay transferred this issue from supabase/supabase-js Feb 16, 2024
@ddx-510
Copy link

ddx-510 commented Jul 4, 2024

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
Copy link

ddx-510 commented Jul 5, 2024

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
Copy link

Yeasirarafat53 commented Oct 20, 2024

same as for me:

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

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

3 participants