Skip to content

Commit 8e38db9

Browse files
committed
Added error descriptions to each of the lifecycle functions
1 parent f154fcc commit 8e38db9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/tasks/overview.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export const taskWithInitReturn = task({
155155
});
156156
```
157157

158+
<Info>
159+
Errors thrown in the `init` function are ignored.
160+
</Info>
161+
158162
### `cleanup` function
159163

160164
This function is called after the `run` function is executed, regardless of whether the run was successful or not. It's useful for cleaning up resources, logging, or other side effects.
@@ -171,10 +175,18 @@ export const taskWithCleanup = task({
171175
});
172176
```
173177

178+
<Info>
179+
Errors thrown in the `cleanup` function will fail the attempt.
180+
</Info>
181+
174182
### `middleware` function
175183

176184
This function is called before the `run` function, it allows you to wrap the run function with custom code.
177185

186+
<Info>
187+
An error thrown in `middleware` is just like an uncaught error in the run function: it will propagate through to `handleError()` and then will fail the attempt (causing a retry).
188+
</Info>
189+
178190
### `onStart` function
179191

180192
When a task run starts, the `onStart` function is called. It's useful for sending notifications, logging, and other side effects. This function will only be called one per run (not per retry). If you want to run code before each retry, use the `init` function.
@@ -204,6 +216,10 @@ export default defineConfig({
204216
});
205217
```
206218

219+
<Info>
220+
Errors thrown in the `onStart` function are ignored.
221+
</Info>
222+
207223
### `onSuccess` function
208224

209225
When a task run succeeds, the `onSuccess` function is called. It's useful for sending notifications, logging, syncing state to your database, or other side effects.
@@ -233,6 +249,10 @@ export default defineConfig({
233249
});
234250
```
235251

252+
<Info>
253+
Errors thrown in the `onSuccess` function are ignored.
254+
</Info>
255+
236256
### `onFailure` function
237257

238258
When a task run fails, the `onFailure` function is called. It's useful for sending notifications, logging, or other side effects. It will only be executed once the task run has exhausted all its retries.
@@ -262,12 +282,20 @@ export default defineConfig({
262282
});
263283
```
264284

285+
<Info>
286+
Errors thrown in the `onFailure` function are ignored.
287+
</Info>
288+
265289
### `handleError` functions
266290

267291
You can define a function that will be called when an error is thrown in the `run` function, that allows you to control how the error is handled and whether the task should be retried.
268292

269293
Read more about `handleError` in our [Errors and Retrying guide](/errors-retrying).
270294

295+
<Info>
296+
Uncaught errors will throw a special internal error of the type `HANDLE_ERROR_ERROR`.
297+
</Info>
298+
271299
## Next steps
272300

273301
<CardGroup>

0 commit comments

Comments
 (0)