question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: no way to specify error meta

See original GitHub issue

Provide environment information

System: OS: macOS 12.4 CPU: (8) arm64 Apple M1 Pro Memory: 97.84 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.7.0 - /opt/homebrew/bin/node npm: 8.15.0 - /opt/homebrew/bin/npm Browsers: Chrome: 105.0.5195.102 Firefox: 104.0.1 Safari: 15.5

Describe the bug

We want to be able to get custom error meta objects. At the moment it doesn’t seem possible.

// Invalid phone number
  if (body.status === '3') {
    throw new TRPCError({
      code: 'BAD_REQUEST',
      message: 'Bad phone number',
      cause: 'invalid-number',
    });
  }

We need to read ‘cause’ as message is a user friendly coding error. It would also be nice to pass meta JSON objects; sometimes error messages need to contain more data.

There seems to be no way to pass though that data.

{ [TRPCClientError: Your request is incomplete and missing the mandatory parameter: number] [cause]: undefined, originalError: undefined, shape: {
    message: 'Your request is incomplete and missing the mandatory parameter: number',
    code: -32600,
    data: {
      code: 'BAD_REQUEST',
      httpStatus: 400,
      stack: ''
      path: 'user.enter-phone-number'
    }
  }, data: {
    code: 'BAD_REQUEST',
    httpStatus: 400,
    stack: ''
    path: 'user.enter-phone-number'
  }, isDone: false, name: 'TRPCClientError' }

To reproduce

^^

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I’d be down to file a PR fixing this bug!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KATTcommented, Sep 8, 2022

This should also work

const router = trpc.router<Context>()
  .formatError(({ shape, error }) => {
    return {
      ...shape,
      data: {
        ...shape.data,
        cause: error.cause,
      },
    };
  })
0reactions
github-actions[bot]commented, Oct 4, 2022

This issue has been locked because it had no new activity for 14 days. If you are running into a similar issue, please create a new issue. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to troubleshoot Meta Pixel error and warning messages ...
This is a list of Meta Pixel errors and warnings you might see in the Diagnostics tab in Meta Events Manager. You can...
Read more >
BUG/RTK Query/Meta is not showing up on throwing error ...
The queryFn when throwing an error does not include the meta payload logUserIn: ... Is their any way to set a custom type...
Read more >
[meta] meta bug - show error pages instead of dialogs for ...
No error dialog is shown, which is good. It appears that IFRAME elements are the culprit. When these specify a URI that is...
Read more >
How to Fix Meta Pixel (Facebook Pixel) Errors and Test Events
On your Meta Business Suite homepage, go to All tools (indicated by the little hamburger menu) and select Events Manager. Now, go to...
Read more >
How to Fix Meta Facebook Pixel Errors and Test Your Events
The Meta Facebook Pixel is a piece of code that you can install on your website to track the different kinds of actions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found