Skip to content

Commit 1635e42

Browse files
authored
fixes issue where a destination plugin loading with an error caused other plugins to be removed (#1076)
1 parent 3c37def commit 1635e42

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.changeset/strong-taxis-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-core': patch
3+
---
4+
5+
Fixes an issue introduced in v1.66.0 that caused analytics plugins to be removed from event processing if a destination threw an error while loading.

packages/core/src/queue/__tests__/event-queue.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CoreAnalytics } from '../../analytics'
44
import { pWhile } from '../../utils/p-while'
55
import * as timer from '../../priority-queue/backoff'
66
import { ContextCancelation } from '../../context'
7-
import { CorePlugin } from '../../plugins'
7+
import { CorePlugin, PluginType } from '../../plugins'
88
import { pTimeout } from '../../callback'
99
import { TestCtx, TestEventQueue } from '../../../test-helpers'
1010

@@ -609,6 +609,32 @@ describe('Flushing', () => {
609609
})
610610
})
611611

612+
describe('register', () => {
613+
it('only filters out failed destinations after loading', async () => {
614+
const eq = new TestEventQueue()
615+
const goodDestinationPlugin = {
616+
...testPlugin,
617+
name: 'good destination',
618+
type: 'destination' as PluginType,
619+
}
620+
const failingPlugin = {
621+
...testPlugin,
622+
name: 'failing',
623+
type: 'destination' as PluginType,
624+
625+
load: () => Promise.reject(new Error('I was born to throw')),
626+
}
627+
628+
const plugins = [testPlugin, goodDestinationPlugin, failingPlugin]
629+
const promises = plugins.map((p) => eq.register(TestCtx.system(), p, ajs))
630+
await Promise.all(promises)
631+
632+
expect(eq.plugins.length).toBe(2)
633+
expect(eq.plugins).toContain(testPlugin)
634+
expect(eq.plugins).toContain(goodDestinationPlugin)
635+
})
636+
})
637+
612638
describe('deregister', () => {
613639
it('remove plugin from plugins list', async () => {
614640
const eq = new TestEventQueue()

packages/core/src/queue/event-queue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export abstract class CoreEventQueue<
6161
error: err,
6262
})
6363

64-
this.plugins = this.plugins.filter((p) => p === plugin)
64+
// Filter out the failed plugin by excluding it from the list
65+
this.plugins = this.plugins.filter((p) => p !== plugin)
6566
})
6667
} else {
6768
await plugin.load(ctx, instance)

0 commit comments

Comments
 (0)