@redthreadlabs/tracelog-client 1.3.1 → 1.4.0

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.
@@ -42,9 +42,12 @@ class EventBuilder {
42
42
  }
43
43
  withError(err) {
44
44
  if (err instanceof Error) {
45
- this._error = { message: withCode(err.message, err.code) };
45
+ this._error = { message: err.message };
46
46
  if (err.name)
47
47
  this._error.type = err.name;
48
+ const code = extractCode(err.code);
49
+ if (code !== undefined)
50
+ this._error.code = code;
48
51
  if (err.stack)
49
52
  this._error.stack = err.stack;
50
53
  }
@@ -57,10 +60,13 @@ class EventBuilder {
57
60
  const message = typeof err.message === 'string' && err.message.length > 0
58
61
  ? err.message
59
62
  : safeJson(err);
60
- this._error = { message: withCode(message, err.code) };
63
+ this._error = { message };
61
64
  if (typeof err.name === 'string' && err.name.length > 0) {
62
65
  this._error.type = err.name;
63
66
  }
67
+ const code = extractCode(err.code);
68
+ if (code !== undefined)
69
+ this._error.code = code;
64
70
  if (typeof err.stack === 'string')
65
71
  this._error.stack = err.stack;
66
72
  }
@@ -87,12 +93,14 @@ class EventBuilder {
87
93
  }
88
94
  }
89
95
  exports.EventBuilder = EventBuilder;
90
- // Append an error code (ShareDB and Node errors carry one) to the message.
91
- function withCode(message, code) {
96
+ // Stringify an error code (ShareDB and Node errors carry one) for the
97
+ // structured `error.code` field. Until 1.4.0 the code was appended to the
98
+ // message text; a dedicated field is facetable downstream.
99
+ function extractCode(code) {
92
100
  if (typeof code === 'string' || typeof code === 'number') {
93
- return `${message} (code: ${code})`;
101
+ return String(code);
94
102
  }
95
- return message;
103
+ return undefined;
96
104
  }
97
105
  // Bounded JSON fallback for objects with no usable message property.
98
106
  function safeJson(obj) {
package/dist/types.d.ts CHANGED
@@ -19,10 +19,13 @@ export interface LogEventItem {
19
19
  message: string;
20
20
  /** Duration in milliseconds (for timed events that aren't span-shaped) */
21
21
  duration?: number;
22
- /** Serialized error info (message, type, stack) */
22
+ /** Serialized error info. `code` is the structured error code (ShareDB,
23
+ * Node `err.code`, etc.) — facetable downstream, unlike a code folded
24
+ * into the message text. */
23
25
  error?: {
24
26
  message: string;
25
27
  type?: string;
28
+ code?: string;
26
29
  stack?: string;
27
30
  };
28
31
  /** Arbitrary key-value event data */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redthreadlabs/tracelog-client",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Lightweight logging client for tracelog — works in React Native and browsers",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -13,7 +13,9 @@
13
13
  ],
14
14
  "scripts": {
15
15
  "build": "tsc",
16
- "prepublishOnly": "npm run build"
16
+ "prepublishOnly": "npm run build",
17
+ "pretest": "npm run build",
18
+ "test": "node --test"
17
19
  },
18
20
  "devDependencies": {
19
21
  "typescript": "latest"