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.

Error thrown inside an async rule are not sent to the fallbackError function

See original GitHub issue

Describe the bug

If an async rule throws inside a chain, the error is not sent to the fallbackError function. The value is null.

Example

const editorIsEventOwner= chain(
  isPromoterStaff,
  rule({ cache: PermissionCache.STRICT })(
    async (_parent: {}, args: { id: string }, ctx: Context) => {
      const { id } = args;
      const event = await findEvent(toInt(id), ctx); // This can throw an Error
      if (!event) return false;
      return event.ownerId === ctx.user?.id;
    }
  )
);

This will correctly not allow the user to proceed if the findEvent fails, but it will not put the Error in the first parameter of the the function.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
stale[bot]commented, Jun 7, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

2reactions
Syttencommented, Jul 31, 2020

I created a wrapper for the rule function. I would be willing to rewrite part of the lib to support more native feature if @maticzav let me. I basically did it with nexus-shield. I think the shift to throw would be better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error thrown inside an async rule are not sent to the ... - GitHub
Describe the bug If an async rule throws inside a chain, the error is not sent to the fallbackError function. The value is...
Read more >
How to Throw Errors From Async Functions in JavaScript?
Throwing errors is a best practice for dealing with unknowns. The same rule applies for every modern language: Java, JavaScript, Python, Ruby.
Read more >
Errors – GraphQL Shield
Shield, by default, catches all errors thrown during resolver execution. ... Rules that return error are treated as failing, therefore not ...
Read more >
Can I throw error in an async function? - Stack Overflow
But I'm using async function, so no res and rej methods are there. So, the question: can I throw errors in async functions?...
Read more >
Common Mistakes in JavaScript Async Function Error Handling
Learn JavaScript Async Function Error Handling, and don't throw an error like a normal synchronous function. Error handling is important in JavaScript flow ......
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