From b4284e4d1a76172d7c7647f22a66b9b877dc6638 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 12 Jan 2025 22:25:50 -0600 Subject: [PATCH 1/4] errrefguide --- .../docs/v4/reference/error-handling.mdx | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/content/docs/v4/reference/error-handling.mdx diff --git a/src/content/docs/v4/reference/error-handling.mdx b/src/content/docs/v4/reference/error-handling.mdx new file mode 100644 index 000000000..5f17dc162 --- /dev/null +++ b/src/content/docs/v4/reference/error-handling.mdx @@ -0,0 +1,57 @@ +--- +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'; + + +- src/ + - commands/ + - events/ + - **error.js** + - index.js + - config.js + - dependencies.d.ts + + + +::: 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) + + +:::caution + + Be careful about errors thrown IN the error handler. + If this happens, a memory leaks occurs and your bot **will crash**. + +::: + From cafecdc5329bfbe74d79939e36f4df33f9ae4191 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 12 Jan 2025 22:32:05 -0600 Subject: [PATCH 2/4] polish --- src/content/docs/v4/reference/error-handling.mdx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/content/docs/v4/reference/error-handling.mdx b/src/content/docs/v4/reference/error-handling.mdx index 5f17dc162..75a3e3cbc 100644 --- a/src/content/docs/v4/reference/error-handling.mdx +++ b/src/content/docs/v4/reference/error-handling.mdx @@ -7,7 +7,7 @@ sidebar: Error handling is important in any application, especially one which has a long lifetime of running. -## Handling errors in command and event modules. +## Handling errors in command and event modules To capture errors, enable the 'error' event in sern's global event manager. @@ -24,12 +24,14 @@ import { FileTree } from '@astrojs/starlight/components'; -::: tip +:::tip + Don't forget to enable event handling! ```js title='src/config.js' - export const events = "./dist/events" +export const events = "./dist/events" ``` -::: + +:: ```js From 3abe33b75d5d4022d3a7676a204cd86c4a41882d Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 12 Jan 2025 22:37:09 -0600 Subject: [PATCH 3/4] fk --- src/content/docs/v4/reference/error-handling.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/v4/reference/error-handling.mdx b/src/content/docs/v4/reference/error-handling.mdx index 75a3e3cbc..9ea35e36f 100644 --- a/src/content/docs/v4/reference/error-handling.mdx +++ b/src/content/docs/v4/reference/error-handling.mdx @@ -31,7 +31,7 @@ Don't forget to enable event handling! export const events = "./dist/events" ``` -:: +::: ```js From daabc51b93763070d96481c3c4b124a24da82e56 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 12 Jan 2025 22:43:16 -0600 Subject: [PATCH 4/4] b --- src/content/docs/v4/reference/conclusion.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/v4/reference/conclusion.mdx b/src/content/docs/v4/reference/conclusion.mdx index 017c8189b..c0b7994d2 100644 --- a/src/content/docs/v4/reference/conclusion.mdx +++ b/src/content/docs/v4/reference/conclusion.mdx @@ -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!