-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.ts
More file actions
26 lines (22 loc) · 828 Bytes
/
stack.ts
File metadata and controls
26 lines (22 loc) · 828 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
/**
* @file 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
}