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
Copy file name to clipboardExpand all lines: apps/docs/content/docs/create/callbacks.mdx
-4
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,6 @@ Starts execution after output parsing has completed if you defined a schema, oth
93
93
.onError(async (args) => {
94
94
/*
95
95
(parameter) args: {
96
-
asAction: boolean
97
96
input: {
98
97
firstName: string;
99
98
lastName: string;
@@ -114,7 +113,6 @@ Starts execution after output parsing has completed if you defined a schema, oth
114
113
115
114
Starts execution after the first encountered `Err` return while executing your SafeFn. Takes in the following parameters:
116
115
117
-
-`asAction`: wether the safe-fn was run as an action (`createAction()()`) or not (`run()`). This can be helpful the narrow down the type of `error`.
118
116
-`unsafeRawInput`: the raw input passed when running your SafeFn. Keep in mind this can contain additional properties when using one SafeFn as the parent of another!
119
117
-`input`: the results of parsing `unsafeRawInput` through your input schema if you defined one and parsing was successful, otherwise `undefined`.
120
118
-`ctx`: the `Ok` value of your parent safe-fn if you defined one and execution was successful, otherwise undefined
@@ -128,7 +126,6 @@ Starts execution after the first encountered `Err` return while executing your S
128
126
.onComplete(async (args) => {
129
127
/*
130
128
(parameter) args: {
131
-
asAction: boolean
132
129
input: {
133
130
firstName: string;
134
131
lastName: string;
@@ -149,7 +146,6 @@ Starts execution after the first encountered `Err` return while executing your S
149
146
150
147
Starts execution after either `onSuccess()` or `onError()` is **called** (not finished). Takes in the following parameters:
151
148
152
-
-`asAction`: wether the safe-fn was run as an action (`createAction()()`) or not (`run()`). This can be helpful the narrow down the type of `error`.
153
149
-`unsafeRawInput`: the raw input passed when running your SafeFn. Keep in mind this can contain additional properties when using one SafeFn as the parent of another!
154
150
-`input`: the results of parsing `unsafeRawInput` through your input schema if you defined one and parsing was successful, otherwise `undefined`.
155
151
-`ctx`: the `Ok` value of your parent safe-fn if you defined one and execution was successful, otherwise undefined
When parsing is not successful, your handler function is not called and the error is returned. As such, the following types are added to the return type of the function:
25
25
26
-
- when using `run()`
27
-
28
-
```ts
29
-
ResultAsync<{
30
-
never,
31
-
{
32
-
code:"INPUT_PARSING";
33
-
cause:z.ZodError<{
34
-
firstName:string;
35
-
lastName:string;
36
-
}>;
37
-
}
38
-
}>;
39
-
```
40
-
41
-
- when using `createAction()()` (full errors are stripped here as classes can not be sent via a Server Action and stack traces should not be shipped to the client)
42
-
43
26
```ts
44
27
ActionResult<
45
28
never,
@@ -62,6 +45,12 @@ ActionResult<
62
45
>;
63
46
```
64
47
48
+
<Callouttype="info">
49
+
The full Zod error is not returned as SafeFn is meant to be used at the edge
50
+
of your application, stack traces should not be sent to the client and it's
51
+
not possible to serialize an instance of `Error`s.
52
+
</Callout>
53
+
65
54
<Callouttype="info">
66
55
When using a [parent](/docs/create/chaining), the schema of the Zod error is
67
56
merged with the possible input parsing errors from all parent SafeFns. This is
When output parsing is not successful, an `Err` is returned. The following types are added to the return type:
136
125
137
-
- when using `run()`
138
-
139
-
```ts
140
-
ResultAsync<{
141
-
never,
142
-
{
143
-
code:"OUTPUT_PARSING";
144
-
cause:z.ZodError<{ fullName:string }>;
145
-
};
146
-
}>;
147
-
```
148
-
149
-
- when using `createAction()()` (full errors are stripped here as classes can not be sent via a Server Action and stack traces should not be shipped to the client)
150
-
151
126
```ts
152
127
ActionResult<
153
128
never,
@@ -161,6 +136,12 @@ ActionResult<
161
136
>;
162
137
```
163
138
139
+
<Callouttype="info">
140
+
The full Zod error is not returned as SafeFn is meant to be used at the edge
141
+
of your application, stack traces should not be sent to the client and it's
142
+
not possible to serialize an instance of `Error`s.
143
+
</Callout>
144
+
164
145
<Callouttype="info">
165
146
When using a [parent](/docs/create/chaining), the schema of the Zod error is
166
147
merged with the possible output parsing errors from all parent SafeFns. This
Often times you want to filter out some specific errors from the client. Typically you'll handle this by calling NeverThrow's own `mapErr()` on your returned/yielded results, however sometimes it can be handy to do this globally for your SafeFn.
6
+
You can modify the error type of the SafeFn by using `.mapErr()`. This is a function that takes in an argument of the original error type (see ), and returns a value that will set the new error type.
Copy file name to clipboardExpand all lines: apps/docs/content/docs/run/return-type.mdx
+1-62
Original file line number
Diff line number
Diff line change
@@ -20,17 +20,6 @@ A union that can contain the following errors:
20
20
21
21
### Input parsing
22
22
23
-
When using `.run()`
24
-
25
-
```ts
26
-
typeE= {
27
-
code:"INPUT_PARSING";
28
-
cause:z.ZodError<T>;
29
-
};
30
-
```
31
-
32
-
when using `.createAction()` full errors are stripped as classes can not be sent via a Server Action and stack traces should not be shipped to the client
33
-
34
23
```ts
35
24
typeE= {
36
25
code:"INPUT_PARSING";
@@ -92,17 +81,6 @@ type E = {
92
81
93
82
### Output parsing
94
83
95
-
When using `.run()`
96
-
97
-
```ts
98
-
typeE= {
99
-
code:"OUTPUT_PARSING";
100
-
cause:z.ZodError<T>;
101
-
};
102
-
```
103
-
104
-
when using `.createAction()` full errors are stripped as classes can not be sent via a Server Action and stack traces should not be shipped to the client
105
-
106
84
```ts
107
85
typeE= {
108
86
code:"OUTPUT_PARSING";
@@ -175,46 +153,7 @@ const child = createSafeFn()
175
153
});
176
154
```
177
155
178
-
The return type of `child.run()` will be:
179
-
180
-
```ts
181
-
typeRes=ResultAsync<
182
-
{
183
-
childOut:string;
184
-
},
185
-
// Merged error from parent and child
186
-
| {
187
-
code:"INPUT_PARSING";
188
-
cause:z.ZodError<{
189
-
parentIn:string;
190
-
childIn:string;
191
-
}>;
192
-
}
193
-
// Yielded error in parent
194
-
| {
195
-
code:"TOO_LOW!";
196
-
}
197
-
// Parent did not specify a catch handler, so default is used
198
-
| {
199
-
code:"UNCAUGHT_ERROR";
200
-
cause:"An uncaught error occurred. You can implement a custom error handler by using `catch()`";
201
-
}
202
-
// Specified in child catch handler
203
-
| {
204
-
code:"Woops!";
205
-
}
206
-
// Output parsing error
207
-
| {
208
-
code:"OUTPUT_PARSING";
209
-
cause:z.ZodError<{
210
-
parentOut:string;
211
-
childOut:string;
212
-
}>;
213
-
}
214
-
>;
215
-
```
216
-
217
-
The result of calling `child.createAction()` through the `useServerAction()` hook will be:
156
+
The return type of `child.run()` or calling `child.createAction()` through the `useServerAction()` hook will be:
0 commit comments