@posthog/core 1.32.0 → 1.32.2

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.
@@ -24,9 +24,7 @@ export declare class PostHogLogs {
24
24
  * Runs the configured `beforeSend` hook(s) on a capture record:
25
25
  * - single fn OR array of fns (chain, left-to-right)
26
26
  * - returning `null` drops the record (logged at info)
27
- * - a thrown error is logged and the chain *continues* with the previous
28
- * result — a buggy user filter must never crash the caller's
29
- * `captureLog()` call
27
+ * - a thrown error is logged and the record is dropped
30
28
  */
31
29
  private _runBeforeSend;
32
30
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logs/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAA4B,MAAM,UAAU,CAAA;AAC3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,KAAK,EAGV,iBAAiB,EACjB,aAAa,EACb,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAEhB,qBAAa,WAAW;IAuBpB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAMzB,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IAhCzC,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,gBAAgB,CAAQ;IAIhC,OAAO,CAAC,uBAAuB,CAAQ;IACvC,OAAO,CAAC,WAAW,CAAC,CAAmC;IAGvD,OAAO,CAAC,aAAa,CAA6B;IAMlD,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,mBAAmB,CAAC,CAAQ;IACpC,OAAO,CAAC,oBAAoB,CAAI;IAChC,OAAO,CAAC,iBAAiB,CAAI;IAC7B,OAAO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;CAMzB"}
@@ -77,6 +77,7 @@ class PostHogLogs {
77
77
  result = next;
78
78
  } catch (e) {
79
79
  this._logger.error("Error in beforeSend function for log:", e);
80
+ return null;
80
81
  }
81
82
  return result;
82
83
  }
@@ -49,6 +49,7 @@ class PostHogLogs {
49
49
  result = next;
50
50
  } catch (e) {
51
51
  this._logger.error("Error in beforeSend function for log:", e);
52
+ return null;
52
53
  }
53
54
  return result;
54
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/core",
3
- "version": "1.32.0",
3
+ "version": "1.32.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -67,7 +67,7 @@
67
67
  }
68
68
  },
69
69
  "dependencies": {
70
- "@posthog/types": "1.386.0"
70
+ "@posthog/types": "1.386.2"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@rslib/core": "0.10.6",
@@ -961,9 +961,8 @@ describe('PostHogLogs', () => {
961
961
  )
962
962
 
963
963
  // Cases that share a "captureLog → assert queue body" shape. Bespoke
964
- // assertions (logger expectations, throw-doesn't-crash, post-chain
965
- // continuation after throw) live in their own `it` blocks below — those
966
- // were warping the table when forced into it.
964
+ // assertions (logger expectations, throw-drops-the-record) live in their
965
+ // own `it` blocks below — those were warping the table when forced into it.
967
966
  type Case = {
968
967
  name: string
969
968
  beforeSend: PostHogLogsConfig['beforeSend']
@@ -1030,10 +1029,7 @@ describe('PostHogLogs', () => {
1030
1029
  expect(logger.info).toHaveBeenCalledWith('Log was rejected in beforeSend function')
1031
1030
  })
1032
1031
 
1033
- it('never crashes the caller when a fn throws — the chain continues with the prior result', () => {
1034
- // Bespoke: needs to verify (a) no throw escapes captureLog, (b) the
1035
- // chain continues with the previous result so a buggy filter degrades
1036
- // to a no-op, and (c) the failure is logged. Doesn't fit the table.
1032
+ it('never crashes the caller when a fn throws — drops the record (fail closed) and logs', () => {
1037
1033
  const thrower = jest.fn(() => {
1038
1034
  throw new Error('bad filter')
1039
1035
  })
@@ -1047,7 +1043,8 @@ describe('PostHogLogs', () => {
1047
1043
  )
1048
1044
 
1049
1045
  expect(() => logs.captureLog({ body: 'hi' })).not.toThrow()
1050
- expect(readQueue(mockInstance)[0].record.body.stringValue).toBe('hi!')
1046
+ expect(readQueue(mockInstance)).toHaveLength(0)
1047
+ expect(after).not.toHaveBeenCalled()
1051
1048
  expect(logger.error).toHaveBeenCalledWith(
1052
1049
  expect.stringContaining('Error in beforeSend function for log:'),
1053
1050
  expect.any(Error)
package/src/logs/index.ts CHANGED
@@ -92,9 +92,7 @@ export class PostHogLogs {
92
92
  * Runs the configured `beforeSend` hook(s) on a capture record:
93
93
  * - single fn OR array of fns (chain, left-to-right)
94
94
  * - returning `null` drops the record (logged at info)
95
- * - a thrown error is logged and the chain *continues* with the previous
96
- * result — a buggy user filter must never crash the caller's
97
- * `captureLog()` call
95
+ * - a thrown error is logged and the record is dropped
98
96
  */
99
97
  private _runBeforeSend(options: CaptureLogOptions): CaptureLogOptions | null {
100
98
  const beforeSend = this._config.beforeSend
@@ -112,9 +110,8 @@ export class PostHogLogs {
112
110
  }
113
111
  result = next
114
112
  } catch (e) {
115
- // Swallow the throw — the chain continues with `result` unchanged so
116
- // a buggy filter degrades to a no-op rather than crashing the app.
117
113
  this._logger.error(`Error in beforeSend function for log:`, e)
114
+ return null
118
115
  }
119
116
  }
120
117
  return result