posthog-node 5.47.7 → 5.47.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,7 @@
1
1
  import { ErrorTracking as CoreErrorTracking } from '@posthog/core';
2
- export declare function addUncaughtExceptionListener(captureFn: (exception: Error, hint: CoreErrorTracking.EventHint) => void, onFatalFn: (exception: Error) => void): void;
3
- export declare function addUnhandledRejectionListener(captureFn: (exception: unknown, hint: CoreErrorTracking.EventHint) => void): void;
2
+ type UnhandledRejectionMode = 'throw' | 'strict' | 'warn' | 'warn-with-error-code' | 'none';
3
+ export declare function getUnhandledRejectionMode(execArgv?: string[], nodeOptions?: string | undefined): UnhandledRejectionMode;
4
+ export declare function addUncaughtExceptionListener(captureFn: (exception: Error, hint: CoreErrorTracking.EventHint) => void, onFatalFn: (exception: Error) => void, mode?: UnhandledRejectionMode): void;
5
+ export declare function addUnhandledRejectionListener(captureFn: (exception: unknown, hint: CoreErrorTracking.EventHint) => void, mode?: UnhandledRejectionMode): void;
6
+ export {};
4
7
  //# sourceMappingURL=autocapture.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"autocapture.d.ts","sourceRoot":"","sources":["../../../src/extensions/error-tracking/autocapture.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AA6ClE,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,iBAAiB,CAAC,SAAS,KAAK,IAAI,EACxE,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,KAAK,IAAI,GACpC,IAAI,CAEN;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,CAAC,SAAS,KAAK,IAAI,GACzE,IAAI,CASN"}
1
+ {"version":3,"file":"autocapture.d.ts","sourceRoot":"","sources":["../../../src/extensions/error-tracking/autocapture.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGlE,KAAK,sBAAsB,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,sBAAsB,GAAG,MAAM,CAAA;AA+D3F,wBAAgB,yBAAyB,CACvC,QAAQ,GAAE,MAAM,EAAsB,EACtC,WAAW,GAAE,MAAM,GAAG,SAAgC,GACrD,sBAAsB,CAKxB;AA6CD,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,iBAAiB,CAAC,SAAS,KAAK,IAAI,EACxE,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,KAAK,IAAI,EACrC,IAAI,GAAE,sBAAyD,GAC9D,IAAI,CAYN;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,CAAC,SAAS,KAAK,IAAI,EAC1E,IAAI,GAAE,sBAAyD,GAC9D,IAAI,CAiBN"}
@@ -25,20 +25,70 @@ var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  addUncaughtExceptionListener: ()=>addUncaughtExceptionListener,
28
- addUnhandledRejectionListener: ()=>addUnhandledRejectionListener
28
+ addUnhandledRejectionListener: ()=>addUnhandledRejectionListener,
29
+ getUnhandledRejectionMode: ()=>getUnhandledRejectionMode
29
30
  });
31
+ const UNHANDLED_REJECTION_OPTION_NAMES = [
32
+ '--unhandled-rejections',
33
+ '--unhandled_rejections'
34
+ ];
35
+ const UNHANDLED_REJECTION_MODES = new Set([
36
+ 'throw',
37
+ 'strict',
38
+ 'warn',
39
+ 'warn-with-error-code',
40
+ 'none'
41
+ ]);
42
+ const STARTUP_EXEC_ARGV = [
43
+ ...globalThis.process?.execArgv ?? []
44
+ ];
45
+ const STARTUP_NODE_OPTIONS = globalThis.process?.env?.NODE_OPTIONS;
46
+ function splitNodeOptions(nodeOptions) {
47
+ const args = [];
48
+ let current = '';
49
+ let isInString = false;
50
+ for(let index = 0; index < nodeOptions.length; index++){
51
+ const character = nodeOptions[index];
52
+ if ('\\' === character && isInString && index + 1 < nodeOptions.length) current += nodeOptions[++index];
53
+ else if (' ' !== character || isInString) if ('"' === character) isInString = !isInString;
54
+ else current += character;
55
+ else if (current) {
56
+ args.push(current);
57
+ current = '';
58
+ }
59
+ }
60
+ if (current) args.push(current);
61
+ return args;
62
+ }
63
+ function findUnhandledRejectionMode(args) {
64
+ let mode;
65
+ for(let index = 0; index < args.length; index++){
66
+ const argument = args[index];
67
+ const optionName = UNHANDLED_REJECTION_OPTION_NAMES.find((name)=>argument === name || argument.startsWith(`${name}=`));
68
+ if (!optionName) continue;
69
+ const value = argument === optionName ? args[++index] : argument.slice(optionName.length + 1);
70
+ if (UNHANDLED_REJECTION_MODES.has(value)) mode = value;
71
+ }
72
+ return mode;
73
+ }
74
+ function getUnhandledRejectionMode(execArgv = STARTUP_EXEC_ARGV, nodeOptions = STARTUP_NODE_OPTIONS) {
75
+ return findUnhandledRejectionMode(execArgv) ?? findUnhandledRejectionMode(splitNodeOptions(nodeOptions ?? '')) ?? 'throw';
76
+ }
77
+ const STARTUP_UNHANDLED_REJECTION_MODE = getUnhandledRejectionMode();
78
+ function captureUncaughtException(captureFn, error, origin) {
79
+ captureFn(error, {
80
+ mechanism: {
81
+ type: 'unhandledRejection' === origin ? 'onunhandledrejection' : 'onuncaughtexception',
82
+ handled: false
83
+ }
84
+ });
85
+ }
30
86
  function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
31
87
  let calledFatalError = false;
32
- return Object.assign((error)=>{
88
+ return Object.assign((error, origin)=>{
33
89
  const userProvidedListenersCount = global.process.listeners('uncaughtException').filter((listener)=>'domainUncaughtExceptionClear' !== listener.name && true !== listener._posthogErrorHandler).length;
34
- const processWouldExit = 0 === userProvidedListenersCount;
35
- captureFn(error, {
36
- mechanism: {
37
- type: 'onuncaughtexception',
38
- handled: false
39
- }
40
- });
41
- if (!calledFatalError && processWouldExit) {
90
+ captureUncaughtException(captureFn, error, origin);
91
+ if (!calledFatalError && 0 === userProvidedListenersCount) {
42
92
  calledFatalError = true;
43
93
  onFatalFn(error);
44
94
  }
@@ -46,22 +96,31 @@ function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
46
96
  _posthogErrorHandler: true
47
97
  });
48
98
  }
49
- function addUncaughtExceptionListener(captureFn, onFatalFn) {
50
- globalThis.process?.on('uncaughtException', makeUncaughtExceptionHandler(captureFn, onFatalFn));
99
+ function addUncaughtExceptionListener(captureFn, onFatalFn, mode = STARTUP_UNHANDLED_REJECTION_MODE) {
100
+ const process = globalThis.process;
101
+ if (!process) return;
102
+ if ('strict' === mode) return void process.on('uncaughtExceptionMonitor', (error, origin)=>captureUncaughtException(captureFn, error, origin));
103
+ process.on('uncaughtException', makeUncaughtExceptionHandler(captureFn, onFatalFn));
51
104
  }
52
- function addUnhandledRejectionListener(captureFn) {
53
- globalThis.process?.on('unhandledRejection', (reason)=>captureFn(reason, {
105
+ function addUnhandledRejectionListener(captureFn, mode = STARTUP_UNHANDLED_REJECTION_MODE) {
106
+ const process = globalThis.process;
107
+ if (!process || 'throw' === mode || 'strict' === mode || 'warn-with-error-code' === mode) return;
108
+ process.on('unhandledRejection', (reason)=>{
109
+ captureFn(reason, {
54
110
  mechanism: {
55
111
  type: 'onunhandledrejection',
56
112
  handled: false
57
113
  }
58
- }));
114
+ });
115
+ });
59
116
  }
60
117
  exports.addUncaughtExceptionListener = __webpack_exports__.addUncaughtExceptionListener;
61
118
  exports.addUnhandledRejectionListener = __webpack_exports__.addUnhandledRejectionListener;
119
+ exports.getUnhandledRejectionMode = __webpack_exports__.getUnhandledRejectionMode;
62
120
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
63
121
  "addUncaughtExceptionListener",
64
- "addUnhandledRejectionListener"
122
+ "addUnhandledRejectionListener",
123
+ "getUnhandledRejectionMode"
65
124
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
66
125
  Object.defineProperty(exports, '__esModule', {
67
126
  value: true
@@ -1,15 +1,64 @@
1
+ const UNHANDLED_REJECTION_OPTION_NAMES = [
2
+ '--unhandled-rejections',
3
+ '--unhandled_rejections'
4
+ ];
5
+ const UNHANDLED_REJECTION_MODES = new Set([
6
+ 'throw',
7
+ 'strict',
8
+ 'warn',
9
+ 'warn-with-error-code',
10
+ 'none'
11
+ ]);
12
+ const STARTUP_EXEC_ARGV = [
13
+ ...globalThis.process?.execArgv ?? []
14
+ ];
15
+ const STARTUP_NODE_OPTIONS = globalThis.process?.env?.NODE_OPTIONS;
16
+ function splitNodeOptions(nodeOptions) {
17
+ const args = [];
18
+ let current = '';
19
+ let isInString = false;
20
+ for(let index = 0; index < nodeOptions.length; index++){
21
+ const character = nodeOptions[index];
22
+ if ('\\' === character && isInString && index + 1 < nodeOptions.length) current += nodeOptions[++index];
23
+ else if (' ' !== character || isInString) if ('"' === character) isInString = !isInString;
24
+ else current += character;
25
+ else if (current) {
26
+ args.push(current);
27
+ current = '';
28
+ }
29
+ }
30
+ if (current) args.push(current);
31
+ return args;
32
+ }
33
+ function findUnhandledRejectionMode(args) {
34
+ let mode;
35
+ for(let index = 0; index < args.length; index++){
36
+ const argument = args[index];
37
+ const optionName = UNHANDLED_REJECTION_OPTION_NAMES.find((name)=>argument === name || argument.startsWith(`${name}=`));
38
+ if (!optionName) continue;
39
+ const value = argument === optionName ? args[++index] : argument.slice(optionName.length + 1);
40
+ if (UNHANDLED_REJECTION_MODES.has(value)) mode = value;
41
+ }
42
+ return mode;
43
+ }
44
+ function getUnhandledRejectionMode(execArgv = STARTUP_EXEC_ARGV, nodeOptions = STARTUP_NODE_OPTIONS) {
45
+ return findUnhandledRejectionMode(execArgv) ?? findUnhandledRejectionMode(splitNodeOptions(nodeOptions ?? '')) ?? 'throw';
46
+ }
47
+ const STARTUP_UNHANDLED_REJECTION_MODE = getUnhandledRejectionMode();
48
+ function captureUncaughtException(captureFn, error, origin) {
49
+ captureFn(error, {
50
+ mechanism: {
51
+ type: 'unhandledRejection' === origin ? 'onunhandledrejection' : 'onuncaughtexception',
52
+ handled: false
53
+ }
54
+ });
55
+ }
1
56
  function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
2
57
  let calledFatalError = false;
3
- return Object.assign((error)=>{
58
+ return Object.assign((error, origin)=>{
4
59
  const userProvidedListenersCount = global.process.listeners('uncaughtException').filter((listener)=>'domainUncaughtExceptionClear' !== listener.name && true !== listener._posthogErrorHandler).length;
5
- const processWouldExit = 0 === userProvidedListenersCount;
6
- captureFn(error, {
7
- mechanism: {
8
- type: 'onuncaughtexception',
9
- handled: false
10
- }
11
- });
12
- if (!calledFatalError && processWouldExit) {
60
+ captureUncaughtException(captureFn, error, origin);
61
+ if (!calledFatalError && 0 === userProvidedListenersCount) {
13
62
  calledFatalError = true;
14
63
  onFatalFn(error);
15
64
  }
@@ -17,15 +66,22 @@ function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
17
66
  _posthogErrorHandler: true
18
67
  });
19
68
  }
20
- function addUncaughtExceptionListener(captureFn, onFatalFn) {
21
- globalThis.process?.on('uncaughtException', makeUncaughtExceptionHandler(captureFn, onFatalFn));
69
+ function addUncaughtExceptionListener(captureFn, onFatalFn, mode = STARTUP_UNHANDLED_REJECTION_MODE) {
70
+ const process = globalThis.process;
71
+ if (!process) return;
72
+ if ('strict' === mode) return void process.on('uncaughtExceptionMonitor', (error, origin)=>captureUncaughtException(captureFn, error, origin));
73
+ process.on('uncaughtException', makeUncaughtExceptionHandler(captureFn, onFatalFn));
22
74
  }
23
- function addUnhandledRejectionListener(captureFn) {
24
- globalThis.process?.on('unhandledRejection', (reason)=>captureFn(reason, {
75
+ function addUnhandledRejectionListener(captureFn, mode = STARTUP_UNHANDLED_REJECTION_MODE) {
76
+ const process = globalThis.process;
77
+ if (!process || 'throw' === mode || 'strict' === mode || 'warn-with-error-code' === mode) return;
78
+ process.on('unhandledRejection', (reason)=>{
79
+ captureFn(reason, {
25
80
  mechanism: {
26
81
  type: 'onunhandledrejection',
27
82
  handled: false
28
83
  }
29
- }));
84
+ });
85
+ });
30
86
  }
31
- export { addUncaughtExceptionListener, addUnhandledRejectionListener };
87
+ export { addUncaughtExceptionListener, addUnhandledRejectionListener, getUnhandledRejectionMode };
@@ -67,6 +67,7 @@ declare class FeatureFlagsPoller {
67
67
  onLoad?: (count: number) => void;
68
68
  private cacheProvider?;
69
69
  private loadingPromise?;
70
+ private pollerStopped;
70
71
  private flagsEtag?;
71
72
  private nextFetchAllowedAt?;
72
73
  private strictLocalEvaluation;
@@ -1 +1 @@
1
- {"version":3,"file":"feature-flags.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAmC,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtH,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAG1G,OAAO,EAAE,2BAA2B,EAA2B,MAAM,SAAS,CAAA;AAe9E,KAAK,oBAAoB,GAAG,OAAO,GAAG,UAAU,GAAG,sBAAsB,CAAA;AAEzE,cAAM,WAAY,SAAQ,KAAK;gBACjB,OAAO,EAAE,MAAM;CAO5B;AAWD,cAAM,sBAAuB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,cAAM,wBAAyB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED,KAAK,yBAAyB,GAAG;IAC/B,cAAc,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,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;
73
73
  this.backOffCount = 0;
74
+ this.pollerStopped = false;
74
75
  this.pollingInterval = pollingInterval;
75
76
  this.personalApiKey = personalApiKey;
76
77
  this.featureFlags = [];
@@ -400,7 +401,6 @@ class FeatureFlagsPoller {
400
401
  clearTimeout(this.poller);
401
402
  this.poller = void 0;
402
403
  }
403
- this.poller = setTimeout(()=>this.loadFeatureFlags(true), this.getPollingInterval());
404
404
  try {
405
405
  let shouldFetch = true;
406
406
  if (this.cacheProvider) try {
@@ -467,6 +467,8 @@ class FeatureFlagsPoller {
467
467
  }
468
468
  } catch (err) {
469
469
  if (err instanceof ClientError) this.onError?.(err);
470
+ } finally{
471
+ if (!this.pollerStopped) this.poller = setTimeout(()=>this.loadFeatureFlags(true), this.getPollingInterval());
470
472
  }
471
473
  }
472
474
  getPersonalApiKeyRequestOptions(method = 'GET', etag) {
@@ -525,7 +527,9 @@ class FeatureFlagsPoller {
525
527
  }
526
528
  }
527
529
  async stopPoller(timeoutMs = 30000) {
530
+ this.pollerStopped = true;
528
531
  clearTimeout(this.poller);
532
+ this.poller = void 0;
529
533
  if (this.cacheProvider) try {
530
534
  const shutdownResult = this.cacheProvider.shutdown();
531
535
  if (shutdownResult instanceof Promise) await (0, core_namespaceObject.raceWithTimeout)(shutdownResult, timeoutMs, ()=>{
@@ -37,6 +37,7 @@ class FeatureFlagsPoller {
37
37
  this.debugMode = false;
38
38
  this.shouldBeginExponentialBackoff = false;
39
39
  this.backOffCount = 0;
40
+ this.pollerStopped = false;
40
41
  this.pollingInterval = pollingInterval;
41
42
  this.personalApiKey = personalApiKey;
42
43
  this.featureFlags = [];
@@ -366,7 +367,6 @@ class FeatureFlagsPoller {
366
367
  clearTimeout(this.poller);
367
368
  this.poller = void 0;
368
369
  }
369
- this.poller = setTimeout(()=>this.loadFeatureFlags(true), this.getPollingInterval());
370
370
  try {
371
371
  let shouldFetch = true;
372
372
  if (this.cacheProvider) try {
@@ -433,6 +433,8 @@ class FeatureFlagsPoller {
433
433
  }
434
434
  } catch (err) {
435
435
  if (err instanceof ClientError) this.onError?.(err);
436
+ } finally{
437
+ if (!this.pollerStopped) this.poller = setTimeout(()=>this.loadFeatureFlags(true), this.getPollingInterval());
436
438
  }
437
439
  }
438
440
  getPersonalApiKeyRequestOptions(method = 'GET', etag) {
@@ -491,7 +493,9 @@ class FeatureFlagsPoller {
491
493
  }
492
494
  }
493
495
  async stopPoller(timeoutMs = 30000) {
496
+ this.pollerStopped = true;
494
497
  clearTimeout(this.poller);
498
+ this.poller = void 0;
495
499
  if (this.cacheProvider) try {
496
500
  const shutdownResult = this.cacheProvider.shutdown();
497
501
  if (shutdownResult instanceof Promise) await raceWithTimeout(shutdownResult, timeoutMs, ()=>{
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "5.47.7";
1
+ export declare const version = "5.47.9";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  version: ()=>version
28
28
  });
29
- const version = '5.47.7';
29
+ const version = '5.47.9';
30
30
  exports.version = __webpack_exports__.version;
31
31
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
32
32
  "version"
package/dist/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- const version = '5.47.7';
1
+ const version = '5.47.9';
2
2
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-node",
3
- "version": "5.47.7",
3
+ "version": "5.47.9",
4
4
  "bugs": {
5
5
  "url": "https://github.com/PostHog/posthog-js/issues"
6
6
  },
@@ -28,7 +28,7 @@
28
28
  "module": "dist/entrypoints/index.node.mjs",
29
29
  "types": "dist/entrypoints/index.node.d.ts",
30
30
  "dependencies": {
31
- "@posthog/core": "^1.46.4"
31
+ "@posthog/core": "^1.46.6"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@edge-runtime/jest-environment": "^4.0.0",
@@ -4,7 +4,94 @@
4
4
 
5
5
  import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
6
6
 
7
- type ErrorHandler = { _posthogErrorHandler: boolean } & ((error: Error) => void)
7
+ type ErrorHandler = { _posthogErrorHandler: boolean } & NodeJS.UncaughtExceptionListener
8
+ type UnhandledRejectionMode = 'throw' | 'strict' | 'warn' | 'warn-with-error-code' | 'none'
9
+
10
+ const UNHANDLED_REJECTION_OPTION_NAMES = ['--unhandled-rejections', '--unhandled_rejections']
11
+ const UNHANDLED_REJECTION_MODES = new Set<UnhandledRejectionMode>([
12
+ 'throw',
13
+ 'strict',
14
+ 'warn',
15
+ 'warn-with-error-code',
16
+ 'none',
17
+ ])
18
+ const STARTUP_EXEC_ARGV = [...(globalThis.process?.execArgv ?? [])]
19
+ const STARTUP_NODE_OPTIONS = globalThis.process?.env?.NODE_OPTIONS
20
+
21
+ function splitNodeOptions(nodeOptions: string): string[] {
22
+ const args: string[] = []
23
+ let current = ''
24
+ let isInString = false
25
+
26
+ for (let index = 0; index < nodeOptions.length; index++) {
27
+ const character = nodeOptions[index]
28
+
29
+ if (character === '\\' && isInString && index + 1 < nodeOptions.length) {
30
+ current += nodeOptions[++index]
31
+ } else if (character === ' ' && !isInString) {
32
+ if (current) {
33
+ args.push(current)
34
+ current = ''
35
+ }
36
+ } else if (character === '"') {
37
+ isInString = !isInString
38
+ } else {
39
+ current += character
40
+ }
41
+ }
42
+
43
+ if (current) {
44
+ args.push(current)
45
+ }
46
+
47
+ return args
48
+ }
49
+
50
+ function findUnhandledRejectionMode(args: string[]): UnhandledRejectionMode | undefined {
51
+ let mode: UnhandledRejectionMode | undefined
52
+
53
+ for (let index = 0; index < args.length; index++) {
54
+ const argument = args[index]
55
+ const optionName = UNHANDLED_REJECTION_OPTION_NAMES.find(
56
+ (name) => argument === name || argument.startsWith(`${name}=`)
57
+ )
58
+ if (!optionName) {
59
+ continue
60
+ }
61
+
62
+ const value = argument === optionName ? args[++index] : argument.slice(optionName.length + 1)
63
+ if (UNHANDLED_REJECTION_MODES.has(value as UnhandledRejectionMode)) {
64
+ mode = value as UnhandledRejectionMode
65
+ }
66
+ }
67
+
68
+ return mode
69
+ }
70
+
71
+ export function getUnhandledRejectionMode(
72
+ execArgv: string[] = STARTUP_EXEC_ARGV,
73
+ nodeOptions: string | undefined = STARTUP_NODE_OPTIONS
74
+ ): UnhandledRejectionMode {
75
+ // Command-line arguments take precedence over NODE_OPTIONS, and the last occurrence wins within each source.
76
+ return (
77
+ findUnhandledRejectionMode(execArgv) ?? findUnhandledRejectionMode(splitNodeOptions(nodeOptions ?? '')) ?? 'throw'
78
+ )
79
+ }
80
+
81
+ const STARTUP_UNHANDLED_REJECTION_MODE = getUnhandledRejectionMode()
82
+
83
+ function captureUncaughtException(
84
+ captureFn: (exception: Error, hint: CoreErrorTracking.EventHint) => void,
85
+ error: Error,
86
+ origin: NodeJS.UncaughtExceptionOrigin
87
+ ): void {
88
+ captureFn(error, {
89
+ mechanism: {
90
+ type: origin === 'unhandledRejection' ? 'onunhandledrejection' : 'onuncaughtexception',
91
+ handled: false,
92
+ },
93
+ })
94
+ }
8
95
 
9
96
  function makeUncaughtExceptionHandler(
10
97
  captureFn: (exception: Error, hint: CoreErrorTracking.EventHint) => void,
@@ -13,32 +100,19 @@ function makeUncaughtExceptionHandler(
13
100
  let calledFatalError: boolean = false
14
101
 
15
102
  return Object.assign(
16
- (error: Error): void => {
17
- // Attaching a listener to `uncaughtException` will prevent the node process from exiting. We generally do not
18
- // want to alter this behaviour so we check for other listeners that users may have attached themselves and adjust
19
- // exit behaviour of the SDK accordingly:
20
- // - If other listeners are attached, do not exit.
21
- // - If the only listener attached is ours, exit.
103
+ (error: Error, origin: NodeJS.UncaughtExceptionOrigin): void => {
104
+ // Like Sentry, we only consider listeners that are currently registered. We intentionally do not reconstruct
105
+ // participation by once listeners or listeners added or removed during dispatch.
22
106
  const userProvidedListenersCount = global.process.listeners('uncaughtException').filter((listener) => {
23
- // There are 2 listeners we ignore:
24
107
  return (
25
- // as soon as we're using domains this listener is attached by node itself
26
108
  listener.name !== 'domainUncaughtExceptionClear' &&
27
- // the handler we register in this integration
28
- (listener as ErrorHandler)._posthogErrorHandler !== true
109
+ (listener as Partial<ErrorHandler>)._posthogErrorHandler !== true
29
110
  )
30
111
  }).length
31
112
 
32
- const processWouldExit = userProvidedListenersCount === 0
33
-
34
- captureFn(error, {
35
- mechanism: {
36
- type: 'onuncaughtexception',
37
- handled: false,
38
- },
39
- })
113
+ captureUncaughtException(captureFn, error, origin)
40
114
 
41
- if (!calledFatalError && processWouldExit) {
115
+ if (!calledFatalError && userProvidedListenersCount === 0) {
42
116
  calledFatalError = true
43
117
  onFatalFn(error)
44
118
  }
@@ -49,16 +123,36 @@ function makeUncaughtExceptionHandler(
49
123
 
50
124
  export function addUncaughtExceptionListener(
51
125
  captureFn: (exception: Error, hint: CoreErrorTracking.EventHint) => void,
52
- onFatalFn: (exception: Error) => void
126
+ onFatalFn: (exception: Error) => void,
127
+ mode: UnhandledRejectionMode = STARTUP_UNHANDLED_REJECTION_MODE
53
128
  ): void {
54
- globalThis.process?.on('uncaughtException', makeUncaughtExceptionHandler(captureFn, onFatalFn))
129
+ const process = globalThis.process
130
+ if (!process) {
131
+ return
132
+ }
133
+
134
+ if (mode === 'strict') {
135
+ process.on('uncaughtExceptionMonitor', (error, origin) => captureUncaughtException(captureFn, error, origin))
136
+ return
137
+ }
138
+
139
+ process.on('uncaughtException', makeUncaughtExceptionHandler(captureFn, onFatalFn))
55
140
  }
56
141
 
57
142
  export function addUnhandledRejectionListener(
58
- captureFn: (exception: unknown, hint: CoreErrorTracking.EventHint) => void
143
+ captureFn: (exception: unknown, hint: CoreErrorTracking.EventHint) => void,
144
+ mode: UnhandledRejectionMode = STARTUP_UNHANDLED_REJECTION_MODE
59
145
  ): void {
60
- globalThis.process?.on('unhandledRejection', (reason: unknown) => {
61
- return captureFn(reason, {
146
+ const process = globalThis.process
147
+
148
+ // Installing an unhandledRejection listener changes Node's behavior in these modes. We intentionally skip capture
149
+ // rather than reproducing Node's fatal handling or warn-with-error-code warning and exit-code semantics in the SDK.
150
+ if (!process || mode === 'throw' || mode === 'strict' || mode === 'warn-with-error-code') {
151
+ return
152
+ }
153
+
154
+ process.on('unhandledRejection', (reason: unknown) => {
155
+ captureFn(reason, {
62
156
  mechanism: {
63
157
  type: 'onunhandledrejection',
64
158
  handled: false,
@@ -107,6 +107,7 @@ class FeatureFlagsPoller {
107
107
  onLoad?: (count: number) => void
108
108
  private cacheProvider?: FlagDefinitionCacheProvider
109
109
  private loadingPromise?: Promise<void>
110
+ private pollerStopped: boolean = false
110
111
  private flagsEtag?: string
111
112
  private nextFetchAllowedAt?: number
112
113
  private strictLocalEvaluation: boolean
@@ -823,8 +824,6 @@ class FeatureFlagsPoller {
823
824
  this.poller = undefined
824
825
  }
825
826
 
826
- this.poller = setTimeout(() => this.loadFeatureFlags(true), this.getPollingInterval())
827
-
828
827
  try {
829
828
  let shouldFetch = true
830
829
  if (this.cacheProvider) {
@@ -975,6 +974,10 @@ class FeatureFlagsPoller {
975
974
  if (err instanceof ClientError) {
976
975
  this.onError?.(err)
977
976
  }
977
+ } finally {
978
+ if (!this.pollerStopped) {
979
+ this.poller = setTimeout(() => this.loadFeatureFlags(true), this.getPollingInterval())
980
+ }
978
981
  }
979
982
  }
980
983
 
@@ -1052,7 +1055,9 @@ class FeatureFlagsPoller {
1052
1055
  }
1053
1056
 
1054
1057
  async stopPoller(timeoutMs: number = 30000): Promise<void> {
1058
+ this.pollerStopped = true
1055
1059
  clearTimeout(this.poller)
1060
+ this.poller = undefined
1056
1061
 
1057
1062
  if (this.cacheProvider) {
1058
1063
  try {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.47.7'
1
+ export const version = '5.47.9'