Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Ensure callback is called when invoking errorHanlder #347

Merged
merged 1 commit into from
Aug 2, 2022

Conversation

timhaley94
Copy link

I work at Trello @ Atlassian.

We use this library, however, it started causing problems for us when throw err was added to the .flush() method. This has been documented here. (#320) For us it was resulting in process crashes when we receive an error message (like a 429) when emitting an event. We had to pin the version of this library to a version before this behavior was added.

I saw, that the errorHandler property was added (#342) and was attempting to update our code to use it, however, when writing a test case, I saw that my event callback was never invoked when errorHandler was present and called

This is because, in the .flush(), everywhere else the method can end, we call done(err), however we do not when looking for and invoking the errorHandler. To reiterate the importance, it's a core bit of functionality of this library that the callbacks for events are invoked when the messages are flushed, so it's needs to occur in this instance as well.

A property, errorHanlder, was recently added which will be called
instead of throwing an error in the .flush() method. This is important
because errors in .flush() could, previously, only be handled via
process.on('uncaughtException', err => { ... }).

However, this property is currently unusable as, when the flush method
invokes this property, it fails to call the callbacks of the events
being flushed.

This commit makes sure the callbacks are called.
@timhaley94
Copy link
Author

I'm not sure if it's important that I open an issue before a PR. If it is, I'm happy to retroactively open an issue.

@@ -381,6 +381,23 @@ test('flush - do not throw on axios failure if errorHandler option is specified'
t.true(errorHandler.calledOnce)
})

test('flush - evoke callback when errorHandler option is specified', async t => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this TDD style. If you comment out the done(err) in index.js, this test will fail.

@timhaley94 timhaley94 changed the title Ensure callback is called when envoking errorHanlder Ensure callback is called when invoking errorHanlder Jul 28, 2022
@pooyaj
Copy link
Contributor

pooyaj commented Aug 2, 2022

thanks for the fix 🙌

@pooyaj pooyaj merged commit d62976f into segmentio:master Aug 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants