@redthreadlabs/tracelog-client 1.3.0 → 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.
- package/dist/EventBuilder.js +44 -1
- package/dist/types.d.ts +4 -1
- package/package.json +4 -2
package/dist/EventBuilder.js
CHANGED
|
@@ -45,6 +45,9 @@ class EventBuilder {
|
|
|
45
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
|
}
|
|
@@ -52,7 +55,20 @@ class EventBuilder {
|
|
|
52
55
|
this._error = { message: err };
|
|
53
56
|
}
|
|
54
57
|
else if (err != null) {
|
|
55
|
-
|
|
58
|
+
// Error-like plain objects (e.g. ShareDB op errors: {code, message}).
|
|
59
|
+
// String(err) would yield the useless '[object Object]'.
|
|
60
|
+
const message = typeof err.message === 'string' && err.message.length > 0
|
|
61
|
+
? err.message
|
|
62
|
+
: safeJson(err);
|
|
63
|
+
this._error = { message };
|
|
64
|
+
if (typeof err.name === 'string' && err.name.length > 0) {
|
|
65
|
+
this._error.type = err.name;
|
|
66
|
+
}
|
|
67
|
+
const code = extractCode(err.code);
|
|
68
|
+
if (code !== undefined)
|
|
69
|
+
this._error.code = code;
|
|
70
|
+
if (typeof err.stack === 'string')
|
|
71
|
+
this._error.stack = err.stack;
|
|
56
72
|
}
|
|
57
73
|
return this;
|
|
58
74
|
}
|
|
@@ -77,3 +93,30 @@ class EventBuilder {
|
|
|
77
93
|
}
|
|
78
94
|
}
|
|
79
95
|
exports.EventBuilder = EventBuilder;
|
|
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) {
|
|
100
|
+
if (typeof code === 'string' || typeof code === 'number') {
|
|
101
|
+
return String(code);
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
// Bounded JSON fallback for objects with no usable message property.
|
|
106
|
+
function safeJson(obj) {
|
|
107
|
+
try {
|
|
108
|
+
const json = JSON.stringify(obj);
|
|
109
|
+
if (typeof json === 'string') {
|
|
110
|
+
return json.length > 500 ? json.slice(0, 500) + '…' : json;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Circular or otherwise unserializable
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
return `[unserializable error: keys=${Object.keys(obj).join(',')}]`;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return Object.prototype.toString.call(obj);
|
|
121
|
+
}
|
|
122
|
+
}
|
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
|
|
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
|
+
"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"
|