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 Handling in the Subscription MessageHandler

See original GitHub issue

The Subscription extension of the EventEmitter class appears to ignore errors that happen within the messageHandler. The EventEmitter listener for ‘error’ and ‘uncaughtException’ on Subscription seems to be eaten or ignored. To test this:

const messageHandler = (message) => {
  throw new Error('always an error');
};

const errorHandler = (err) => {
  logger.error('caught an error, continuing on');
};

subscription.on('message', messageHandler);
subscription.on('error', errorHandler);

‘error’ doesn’t catch and the app crashes, we found the only way around this is to emit the error to the app instead of throwing, then handle it at the app layer, but that is undesirable for being able to handle the errors gracefully from our pubsub codebase and is really hacky passing the app down to our subscription service.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
stephenpluspluscommented, Aug 28, 2019

I think if you use the scope of the message handler, you can emit right there and your subscriber error handler will catch it. So, something like:

const messageHandler = function() {
  // ^__ note this doesn't use arrow functions, which
  // would persist the scope of the outer function 
  if (errorCondition) {
    this.emit('error', new Error('Message'))
  }
}

Or, you can just emit it right on the subscription instance, subscription.emit('error', new Error('Message')).

0reactions
callmehiphopcommented, Sep 4, 2019

This seems pretty specific to @stoked10’s implementation, so I don’t think we need to add any samples for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring integration JDBCMessageHandler error handling ...
My intent is that any exceptions or errors will be caught and rerouted from this subflow level, where the message is complete, to...
Read more >
Subscribe with error listener | Cloud Pub/Sub Documentation
Handles errors when subscribing throws an error. ... Setup an error handler for the subscription session .then([](future<google::cloud::Status> f) {
Read more >
Error Handling - Spring
Spring Integration supports error handling for its components by publishing errors to a message channel. Specifically, the Exception becomes the ...
Read more >
Service Bus messaging exceptions - Azure - Microsoft Learn
This article provides a list of Azure Service Bus messaging exceptions and suggested actions to taken when the exception occurs.
Read more >
5. Error Handling — Advanced Message Processing System ...
When using asynchronous message processing, exceptions thrown form the message handler are silently absorbed by the AMPS C++ client by default. The AMPS...
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