You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bf63585
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: apps/documentation-website/src/app/docs/comparison/page.md
+40-34Lines changed: 40 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Comparison with try-catch
3
3
---
4
4
5
-
See how `safe` compares to traditional try-catch error handling. {% .lead %}
5
+
See how `@cometloop/safe` compares to traditional try-catch error handling — and how `createSafe` keeps call sites as clean as possible. {% .lead %}
6
6
7
7
---
8
8
@@ -43,18 +43,35 @@ async function processOrder(orderId: string) {
43
43
44
44
---
45
45
46
-
## With safe utilities
46
+
## With createSafe (recommended)
47
+
48
+
The best way to use `@cometloop/safe` is with `createSafe`. Configure error handling once, wrap your functions, and the call site looks like normal code:
49
+
50
+
```ts
51
+
// Configure once — in a shared module like lib/safe.ts
Copy file name to clipboardExpand all lines: apps/documentation-website/src/app/docs/create-safe/page.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,18 @@
2
2
title: createSafe
3
3
---
4
4
5
-
Creates a pre-configured safe instance with a fixed error mapping function and optional default hooks. The error type is automatically inferred from the `parseError` return type. {% .lead %}
5
+
The recommended way to use `@cometloop/safe`. Creates a pre-configured safe instance so your call sites stay clean and minimal — just a normal function call, no extra configuration. {% .lead %}
6
6
7
7
---
8
8
9
9
## When to use createSafe
10
10
11
-
- You want consistent error mapping across multiple operations
12
-
- You need default logging/analytics hooks for all operations
13
-
- You want to avoid repeating `parseError` on every call
11
+
`createSafe` is the best way to use this library. The goal is simple: **move all error handling configuration out of your call sites** so they read like normal function calls.
12
+
13
+
- You want call sites that are clean and minimal — no inline `parseError`, no options objects
14
+
- You want consistent error mapping across multiple operations without repeating yourself
15
+
- You need default logging/analytics hooks that run automatically
16
+
- You want to wrap functions once and call them everywhere like any other function
The returned instance has `sync`, `async`, `wrap`, and `wrapAsync` methods — all pre-configured with the error type. See [Types](/docs/types) for the full `SafeInstance<E>` definition.
311
+
The returned instance has `sync`, `async`, `wrap`, `wrapAsync`, `all`, and `allSettled` methods — all pre-configured with the error type. The `all` and `allSettled` methods accept raw async functions (not pre-wrapped `Promise<SafeResult>` entries). See [Types](/docs/types) for the full `SafeInstance<E>` definition.
If `parseResult` throws, the error is caught and processed through `parseError`. For async operations with retry, a `parseResult` throw counts as a failure and triggers retry logic.
162
+
If `parseResult` throws, the error is routed through the standard error path — just like any error thrown by the wrapped function. It goes through `parseError` (if provided), triggers `onError` and `onSettled`, and returns `[null, error]`.
0 commit comments