-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.ts
More file actions
27 lines (23 loc) · 833 Bytes
/
stack.ts
File metadata and controls
27 lines (23 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* @fileoverview Stack-trace extractor with cause-chain support.
* `errorStack` returns the cause-aware stack via pony-cause's
* `stackWithCauses` for Errors, and `undefined` for non-Error values
* so callers can log conditionally. `stackWithCauses` is re-exported
* for direct use.
*/
import { stackWithCauses } from '../external/pony-cause'
import { isError } from './predicates'
export { stackWithCauses }
/**
* Extract a stack trace (with causes) from any caught value.
*
* Returns the cause-aware stack via {@link stackWithCauses} for Errors;
* returns `undefined` for non-Error values, so callers can
* `logger.error(msg, { stack: errorStack(e) })` safely.
*/
export function errorStack(value: unknown): string | undefined {
if (isError(value)) {
return stackWithCauses(value)
}
return undefined
}