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.

modify method exceptions are not catched

See original GitHub issue

Hi,

Exceptions in modify method are not catched by .catch

knex.select()
    .from('Account')
    .modify(function(qb) {
        throw new Error('ERROR HERE');
    })
    .then(r => {})
    .catch(err => console.log('Catched Error:', err));

// Throws: ERROR HERE

On the other hand

knex.select()
    .from('Account')
    .where(function() {
        throw new Error('ERROR HERE');
    })
    .then(r => {})
    .catch(err => console.log('Catched Error:', err));

// Throws: Catched Error: ERROR HERE

Regards,

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
johanneslumpecommented, Jun 24, 2016

@elhigu Your second version could be even nicer by just using Promise.try (when using bluebird):

return Promise
  .try(() => (
    knex
      .select()
      .from('some_table')
      .where('Address.organizationId', 1)
      .modify(rqlToKnex, rql)
  ))
  .then(r => reply({ result: r }))
  .catch(err => reply(err));  
0reactions
ozumcommented, Jun 24, 2016

@elhigu, I mean, I could not find a workaround without adding further nested code, otherwise second workaround is totally acceptable, and I already applied second one in a couple of places. However for another larger project I have, I wish I had small number of modify methods.

@johanneslumpe, also nice suggestions.

Thanks both of you guys for your helps and suggestions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can you add use a method that throws an exception ...
Sometimes when the JDK declares a method, e.g. Integer.parseInt(String s) it throws a NumberFormatException , yet when the method is called you ...
Read more >
Best Practices for exceptions - .NET - Microsoft Learn
Learn best practices for exceptions, such as using try/catch/finally, handling common conditions without exceptions, and using predefined .
Read more >
Specifying the Exceptions Thrown by a Method
If the writeList method doesn't catch the checked exceptions that can occur within it, the writeList method must specify that it can throw...
Read more >
Exceptions and Error Handling, C++ FAQ - Standard C++
But MFC seems to encourage the use of catch-by-pointer; should I do the same? ... Do not use exceptions as simply another way...
Read more >
9 Best Practices to Handle Java Exceptions - Stackify
If you use Throwable in a catch clause, it will not only catch all exceptions; it will also catch all errors. Errors are...
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