11 Commits

Author SHA1 Message Date
Jacob Nguyen
515d2ced78 Update error-handling.mdx 2025-01-18 12:49:19 -06:00
Jacob Nguyen
8e9d895d1a Update error-handling.mdx 2025-01-15 19:41:40 -06:00
Jacob Nguyen
5055daac9b fa
Some checks failed
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
2025-01-14 23:19:52 -06:00
Jacob Nguyen
1da3e57866 sdf 2025-01-14 23:14:36 -06:00
Jacob Nguyen
9d2c3f6582 Update error-handling.mdx
Some checks failed
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
2025-01-13 10:33:10 -06:00
Jacob Nguyen
d5cee30e4f Merge pull request #76 from sern-handler/error-handling-ref
Some checks are pending
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Waiting to run
errrefguide
2025-01-12 22:43:37 -06:00
Jacob Nguyen
daabc51b93 b 2025-01-12 22:43:16 -06:00
Jacob Nguyen
3abe33b75d fk 2025-01-12 22:37:09 -06:00
Jacob Nguyen
cafecdc532 polish 2025-01-12 22:32:05 -06:00
Jacob Nguyen
b4284e4d1a errrefguide 2025-01-12 22:25:50 -06:00
Jacob Nguyen
21f70725bb Merge pull request #75 from sern-handler/jacoobes-patch-1
Update setup.ts
2025-01-12 21:53:32 -06:00
3 changed files with 67 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@lunariajs/core/config.schema.json",
"repository": {
"name": "durocodes/sern-website"
"name": "sern-handler/website"
},
"defaultLocale": {
"label": "English",

View File

@@ -2,7 +2,7 @@
title: Conclusion
description: Thank you for reading the sern guide
sidebar:
order: 9
order: 10
---
If you reached this far, thank you for reading!

View File

@@ -0,0 +1,65 @@
---
title: Error handling
description: Properly handle unexpected errors.
sidebar:
order: 9
---
Error handling is important in any application, especially one which has a long lifetime of running.
## Handling errors in command and event modules
To capture errors, enable the 'error' event in sern's global event manager.
import { FileTree } from '@astrojs/starlight/components';
<FileTree>
- src/
- commands/
- events/
- **error.js**
- index.js
- config.js
- dependencies.d.ts
</FileTree>
:::tip
Don't forget to enable event handling!
```js title='src/config.js'
export const events = "./dist/events"
```
:::
```js
import { EventType, eventModule } from '@sern/handler'
export default eventModule({
type: EventType.Sern,
name: 'error',
execute: (err) => {
console.log('caught', err)
}
})
```
If the error handler is not set, sern's behavior is to crash the application.
This respects [node.js's default behavior](https://nodejs.org/api/events.html#error-events)
:::tip
enable `handleModuleErrors` to handle errors that occur within modules.
:::
:::caution
Be careful about errors thrown IN the error handler.
If this happens, a memory leaks occurs and your bot **will crash**.
:::