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

Custom error object appears as [Object object] #31670

Closed
mozeryansky opened this issue Nov 22, 2021 · 10 comments · Fixed by #33159
Closed

Custom error object appears as [Object object] #31670

mozeryansky opened this issue Nov 22, 2021 · 10 comments · Fixed by #33159
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. good first issue Easy to fix issues, good for newcomers

Comments

@mozeryansky
Copy link
Contributor

mozeryansky commented Nov 22, 2021

What version of Next.js are you using?

12.0.4

What version of Node.js are you using?

14.18.1

What browser are you using?

Firefox

What operating system are you using?

macOS

How are you deploying your application?

next

Describe the Bug

I'm using supabase with nextjs, a postgres error thrown is reported as "[object Object]" instead of the contents.

The issue originates in next-server.js and next-dev-server.js from:
const err = (0, _isError).default(error) ? error : error ? new Error(error + '') : null;

> error
{hint: 'If a new foreign key between these entities wa…the database, try reloading the schema cache.', message: 'Could not find a relationship between products and prices in the schema cache'}

> error + ''
'[object Object]'

Expected Behavior

To treat print the object as is instead of converting to a string.

To Reproduce

  1. From the example npx create-next-app -e https://github.com/vercel/nextjs-subscription-payments nextjs-subscription-payments
  2. Set the NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY in the .env.local
  3. npm run dev

The error is reproduced assuming the database isn't setup and causes the postgres error.

@mozeryansky mozeryansky added the bug Issue was opened via the bug report template. label Nov 22, 2021
@mozeryansky
Copy link
Contributor Author

Changing the line to stringify object errors resolves the issue, but I'm not sure it's the best approach.

var err = undefined
if (typeof error === "object") {
    err = JSON.stringify(error)
} else {
    err = (0, _isError).default(error) ? error : error ? new Error(error + '') : null;
}

@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers type: needs investigation Developer Experience Issues related to Next.js logs, Error overlay, etc. labels Nov 26, 2021
@awareness481
Copy link
Contributor

awareness481 commented Nov 27, 2021

I believe changing

const err = isError(error) ? error : error ? new Error(error + '') : null
to const err = isError(error) ? error : error ? new Error(JSON.stringify(error)) : null should be enough. Since this code appears a lot in the codebase it would probably be better to replace all its instances I'd guess.

Do you need help opening a PR @mozeryansky ?

As a sidenote, perhaps isError could be changed to && ( 'name' in err || 'message' in err)? (although this would probably require additional refactoring)

@mozeryansky
Copy link
Contributor Author

@awareness481 Great suggestion. I'll make a PR now.

@mozeryansky
Copy link
Contributor Author

mozeryansky commented Nov 27, 2021

The fix was simple but I had trouble testing a local built version of next. I ended up making the changes to the nextjs package in the node_modules folder in order to verify the changes. When I used a fresh checkout of nextjs and used yarn build the sample project would show a hook error
Screen Shot 2021-11-27 at 2 58 49 AM
:

@Manikanta-20
Copy link

Facing same issue on iOS browsers(Safari, chrome, firefox)
Any comparability issues?
using nextjs + custom server (express.js) nextjs v10.2.3, node v14

@Karan190
Copy link

hey how to run your application. I can solve your issue.

@mozeryansky
Copy link
Contributor Author

hey how to run your application. I can solve your issue.

I already solved it in PR #31866

@mozeryansky
Copy link
Contributor Author

mozeryansky commented Jan 10, 2022

Except I can't get any maintainer to respond. I tried commenting in the PR a few times, and I've messaged a couple of them in Twitter directly. No response.

@Karan190
Copy link

Karan190 commented Jan 10, 2022 via email

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants