@pmate/log-sdk 0.6.0 → 0.6.1
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/errors.js +18 -0
- package/package.json +1 -1
package/dist/errors.js
CHANGED
|
@@ -11,12 +11,30 @@ export function errorInput(error, context = {}) {
|
|
|
11
11
|
}
|
|
12
12
|
}).slice(0, 4000);
|
|
13
13
|
const value = error instanceof Error ? error : new Error("Non-Error exception");
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
const describe = (input, depth = 0) => {
|
|
16
|
+
if (!input || typeof input !== "object" || depth >= 3 || seen.has(input))
|
|
17
|
+
return undefined;
|
|
18
|
+
seen.add(input);
|
|
19
|
+
const item = input;
|
|
20
|
+
const diagnostic = {};
|
|
21
|
+
for (const key of ["source", "stage", "database", "tables", "mode", "attempt"]) {
|
|
22
|
+
const entry = item.diagnostic?.[key];
|
|
23
|
+
if (typeof entry === "string")
|
|
24
|
+
diagnostic[key] = clean(entry);
|
|
25
|
+
else if (typeof entry === "number" && Number.isFinite(entry))
|
|
26
|
+
diagnostic[key] = entry;
|
|
27
|
+
}
|
|
28
|
+
return { name: clean(item.name ?? "Error"), message: clean(item.message ?? ""), ...(item.stack ? { stack: clean(item.stack) } : {}), ...(Object.keys(diagnostic).length ? { diagnostic } : {}), ...(item.cause ? { cause: describe(item.cause, depth + 1) } : {}), ...(item.inner ? { inner: describe(item.inner, depth + 1) } : {}) };
|
|
29
|
+
};
|
|
30
|
+
const details = describe(value);
|
|
14
31
|
return { data: {
|
|
15
32
|
event: context.fatal ? "runtime.crash" : "runtime.error",
|
|
16
33
|
errorName: clean(value.name), message: clean(value.message),
|
|
17
34
|
...(value.stack ? { stack: clean(value.stack) } : {}),
|
|
18
35
|
...(context.operation ? { operation: context.operation } : {}),
|
|
19
36
|
...(context.componentStack ? { componentStack: clean(context.componentStack) } : {}),
|
|
37
|
+
...(details ? { errorDetails: details } : {}),
|
|
20
38
|
fatal: context.fatal ?? false,
|
|
21
39
|
} };
|
|
22
40
|
}
|