@seedcord/errors 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,55 @@
1
- <p align="center">
1
+ <div align="center">
2
2
  <picture>
3
3
  <source media="(prefers-color-scheme: dark)" srcset="https://cdn.seedcord.org/assets/wordmark-dark.webp" />
4
4
  <img src="https://cdn.seedcord.org/assets/wordmark-light.webp" alt="seedcord" width="440" />
5
5
  </picture>
6
- </p>
6
+ </div>
7
7
 
8
- ---
8
+ <div align="center">
9
+ <h3>The whole Discord bot, wired and typed</h3>
10
+ <a href="https://seedcord.org">Website</a> ·
11
+ <a href="https://guide.seedcord.org">Guide</a> ·
12
+ <a href="https://docs.seedcord.org">Reference</a> ·
13
+ <a href="https://discord.gg/DzFxY58WXf">Discord</a>
14
+ </div>
9
15
 
10
- _This repository is a work in progress._
16
+ <br />
11
17
 
12
- - There are no stable releases yet but changes are being made actively.
13
- - Until a major v1.0.0 release for seedcord, expect breaking changes in minor versions.
14
- - Documentation will come soon as well!
18
+ <div align="center">
15
19
 
16
- If you'd like to try it out, you can check out the code in `mock`
20
+ [![npm](https://img.shields.io/npm/v/@seedcord/errors?style=flat-square&logo=npm&logoColor=c8341f&label=&labelColor=1f1f1f&color=c8341f)](https://www.npmjs.com/package/@seedcord/errors) [![node](https://img.shields.io/node/v/@seedcord/errors?style=flat-square&label=node&labelColor=1f1f1f&color=4d7d33)](https://nodejs.org) [![license](https://img.shields.io/npm/l/@seedcord/errors?style=flat-square&label=license&labelColor=1f1f1f&color=f8f6e8)](LICENSE)
21
+
22
+ </div>
23
+
24
+ ## About
25
+
26
+ `@seedcord/errors` holds every error seedcord throws. Each one carries a registered code from `SeedcordErrorCode`, so a caller can branch on one specific failure.
27
+
28
+ Framework code never throws a raw `Error`. A third-party throw may be translated into one of these before you catch it.
29
+
30
+ Until v1.0.0, minor versions can break.
31
+
32
+ ## Installation
33
+
34
+ Your transport already re-exports this.
35
+
36
+ ```sh
37
+ pnpm add @seedcord/errors
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ `isSeedcordError` narrows on the class and the code together:
43
+
44
+ ```ts
45
+ import { isSeedcordError, SeedcordErrorCode } from '@seedcord/errors';
46
+
47
+ try {
48
+ await run();
49
+ } catch (error) {
50
+ if (isSeedcordError(error, 'SeedcordError', SeedcordErrorCode.CliCancelled)) return;
51
+ throw error;
52
+ }
53
+ ```
54
+
55
+ Called with one argument it narrows to any seedcord error.
@@ -5,22 +5,18 @@ import chalk from "chalk";
5
5
  * All Seedcord error codes.
6
6
  */
7
7
  let SeedcordErrorCode = /* @__PURE__ */ function(SeedcordErrorCode) {
8
- /** DISCORD_BOT_TOKEN is not present in the environment. */
9
- SeedcordErrorCode[SeedcordErrorCode["ConfigMissingDiscordToken"] = 1001] = "ConfigMissingDiscordToken";
10
- /** DISCORD_BOT_TOKEN is present but fails validation. */
11
- SeedcordErrorCode[SeedcordErrorCode["ConfigIncorrectDiscordToken"] = 1002] = "ConfigIncorrectDiscordToken";
12
8
  /** One or more configured emojis could not be resolved at startup. */
13
- SeedcordErrorCode[SeedcordErrorCode["ConfigEmojiUnresolved"] = 1003] = "ConfigEmojiUnresolved";
9
+ SeedcordErrorCode[SeedcordErrorCode["ConfigEmojiUnresolved"] = 1001] = "ConfigEmojiUnresolved";
14
10
  /** A webhook reporter's env var is set but fails webhook URL validation. */
15
- SeedcordErrorCode[SeedcordErrorCode["ConfigWebhookUrlInvalid"] = 1004] = "ConfigWebhookUrlInvalid";
11
+ SeedcordErrorCode[SeedcordErrorCode["ConfigWebhookUrlInvalid"] = 1002] = "ConfigWebhookUrlInvalid";
16
12
  /** A configured webhook does not exist on Discord (deleted, or a wrong id or token). */
17
- SeedcordErrorCode[SeedcordErrorCode["ConfigWebhookNotFound"] = 1005] = "ConfigWebhookNotFound";
18
- /** DISCORD_PUBLIC_KEY is not present in the environment. */
19
- SeedcordErrorCode[SeedcordErrorCode["ConfigMissingPublicKey"] = 1006] = "ConfigMissingPublicKey";
20
- /** DISCORD_PUBLIC_KEY is present but fails validation. */
21
- SeedcordErrorCode[SeedcordErrorCode["ConfigIncorrectPublicKey"] = 1007] = "ConfigIncorrectPublicKey";
13
+ SeedcordErrorCode[SeedcordErrorCode["ConfigWebhookNotFound"] = 1003] = "ConfigWebhookNotFound";
22
14
  /** The generated route manifest was imported before `seedcord build` generated it. */
23
- SeedcordErrorCode[SeedcordErrorCode["ConfigManifestNotGenerated"] = 1008] = "ConfigManifestNotGenerated";
15
+ SeedcordErrorCode[SeedcordErrorCode["ConfigManifestNotGenerated"] = 1004] = "ConfigManifestNotGenerated";
16
+ /** A required environment variable is not present. */
17
+ SeedcordErrorCode[SeedcordErrorCode["ConfigMissingEnv"] = 1005] = "ConfigMissingEnv";
18
+ /** An environment variable is present and fails validation. */
19
+ SeedcordErrorCode[SeedcordErrorCode["ConfigInvalidEnv"] = 1006] = "ConfigInvalidEnv";
24
20
  /** Attempted to add lifecycle tasks after startup already completed. */
25
21
  SeedcordErrorCode[SeedcordErrorCode["LifecycleAddAfterCompletion"] = 1101] = "LifecycleAddAfterCompletion";
26
22
  /** Attempted to add lifecycle tasks while startup is still running. */
@@ -57,18 +53,16 @@ let SeedcordErrorCode = /* @__PURE__ */ function(SeedcordErrorCode) {
57
53
  SeedcordErrorCode[SeedcordErrorCode["CoreAccessorUnresolved"] = 1210] = "CoreAccessorUnresolved";
58
54
  /** Interaction middleware decorated with disallowed event filters. */
59
55
  SeedcordErrorCode[SeedcordErrorCode["DecoratorInteractionEventFilter"] = 1301] = "DecoratorInteractionEventFilter";
60
- /** A decorator could not find the original method being decorated. */
61
- SeedcordErrorCode[SeedcordErrorCode["DecoratorMethodNotFound"] = 1302] = "DecoratorMethodNotFound";
62
56
  /** A command decorator attempted to re-register an existing command scope. */
63
- SeedcordErrorCode[SeedcordErrorCode["DecoratorCommandAlreadyRegistered"] = 1303] = "DecoratorCommandAlreadyRegistered";
57
+ SeedcordErrorCode[SeedcordErrorCode["DecoratorCommandAlreadyRegistered"] = 1302] = "DecoratorCommandAlreadyRegistered";
64
58
  /** A global command decorator specified guild IDs, which is not allowed. */
65
- SeedcordErrorCode[SeedcordErrorCode["DecoratorCommandGlobalWithGuilds"] = 1304] = "DecoratorCommandGlobalWithGuilds";
59
+ SeedcordErrorCode[SeedcordErrorCode["DecoratorCommandGlobalWithGuilds"] = 1303] = "DecoratorCommandGlobalWithGuilds";
66
60
  /** A guild command decorator omitted the required guild ID list. */
67
- SeedcordErrorCode[SeedcordErrorCode["DecoratorCommandGuildWithoutGuilds"] = 1305] = "DecoratorCommandGuildWithoutGuilds";
61
+ SeedcordErrorCode[SeedcordErrorCode["DecoratorCommandGuildWithoutGuilds"] = 1304] = "DecoratorCommandGuildWithoutGuilds";
68
62
  /** Middleware priority provided by the decorator was not a finite number. */
69
- SeedcordErrorCode[SeedcordErrorCode["DecoratorInvalidMiddlewarePriority"] = 1306] = "DecoratorInvalidMiddlewarePriority";
63
+ SeedcordErrorCode[SeedcordErrorCode["DecoratorInvalidMiddlewarePriority"] = 1305] = "DecoratorInvalidMiddlewarePriority";
70
64
  /** A WebhookLog subclass is missing its `@WebhookUrl` decorator. */
71
- SeedcordErrorCode[SeedcordErrorCode["DecoratorWebhookUrlMissing"] = 1307] = "DecoratorWebhookUrlMissing";
65
+ SeedcordErrorCode[SeedcordErrorCode["DecoratorWebhookUrlMissing"] = 1306] = "DecoratorWebhookUrlMissing";
72
66
  /** Two interaction handlers registered the same route within a scope. */
73
67
  SeedcordErrorCode[SeedcordErrorCode["InteractionDuplicateRoute"] = 1401] = "InteractionDuplicateRoute";
74
68
  /** Two different interaction middleware classes share a class name. */
@@ -133,6 +127,8 @@ let SeedcordErrorCode = /* @__PURE__ */ function(SeedcordErrorCode) {
133
127
  SeedcordErrorCode[SeedcordErrorCode["ColorOutOfRange"] = 1902] = "ColorOutOfRange";
134
128
  /** A plugin's constructor rejected its options through `rejectOptions`. */
135
129
  SeedcordErrorCode[SeedcordErrorCode["PluginOptionsRejected"] = 2001] = "PluginOptionsRejected";
130
+ /** Two or more plugins threw while disposing. */
131
+ SeedcordErrorCode[SeedcordErrorCode["PluginDisposeFailures"] = 2002] = "PluginDisposeFailures";
136
132
  /** Mongoose service class is missing the `@RegisterMongooseService` decorator. */
137
133
  SeedcordErrorCode[SeedcordErrorCode["PluginMongooseServiceDecoratorMissing"] = 2101] = "PluginMongooseServiceDecoratorMissing";
138
134
  /** Mongoose client failed to establish a connection. */
@@ -173,76 +169,54 @@ let SeedcordErrorCode = /* @__PURE__ */ function(SeedcordErrorCode) {
173
169
  SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidExport"] = 3101] = "CliConfigInvalidExport";
174
170
  /** Config is missing the required instance string. */
175
171
  SeedcordErrorCode[SeedcordErrorCode["CliConfigMissingInstance"] = 3102] = "CliConfigMissingInstance";
176
- /** Config root was provided but not a string. */
177
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidRoot"] = 3103] = "CliConfigInvalidRoot";
178
172
  /** Unable to locate a Seedcord config file. */
179
- SeedcordErrorCode[SeedcordErrorCode["CliConfigNotFound"] = 3104] = "CliConfigNotFound";
173
+ SeedcordErrorCode[SeedcordErrorCode["CliConfigNotFound"] = 3103] = "CliConfigNotFound";
180
174
  /** CLI entry file does not exist. */
181
- SeedcordErrorCode[SeedcordErrorCode["CliEntryNotFound"] = 3105] = "CliEntryNotFound";
175
+ SeedcordErrorCode[SeedcordErrorCode["CliEntryNotFound"] = 3104] = "CliEntryNotFound";
182
176
  /** tsx failed to import the provided entry file. */
183
- SeedcordErrorCode[SeedcordErrorCode["CliTsxImportFailed"] = 3106] = "CliTsxImportFailed";
177
+ SeedcordErrorCode[SeedcordErrorCode["CliTsxImportFailed"] = 3105] = "CliTsxImportFailed";
184
178
  /** Native import and jiti fallback both failed. */
185
- SeedcordErrorCode[SeedcordErrorCode["CliImportFailed"] = 3107] = "CliImportFailed";
179
+ SeedcordErrorCode[SeedcordErrorCode["CliImportFailed"] = 3106] = "CliImportFailed";
186
180
  /** Seedcord instance export is missing a start() method. */
187
- SeedcordErrorCode[SeedcordErrorCode["CliInstanceInvalid"] = 3108] = "CliInstanceInvalid";
181
+ SeedcordErrorCode[SeedcordErrorCode["CliInstanceInvalid"] = 3107] = "CliInstanceInvalid";
188
182
  /** Seedcord instance threw during startup. */
189
- SeedcordErrorCode[SeedcordErrorCode["CliStartFailed"] = 3109] = "CliStartFailed";
183
+ SeedcordErrorCode[SeedcordErrorCode["CliStartFailed"] = 3108] = "CliStartFailed";
190
184
  /** Config is missing the required entry string. */
191
- SeedcordErrorCode[SeedcordErrorCode["CliConfigMissingEntry"] = 3110] = "CliConfigMissingEntry";
192
- /** Config build options must be an object when provided. */
193
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidBuild"] = 3111] = "CliConfigInvalidBuild";
194
- /** Config build outDir must be a string when provided. */
195
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidBuildOutDir"] = 3112] = "CliConfigInvalidBuildOutDir";
196
- /** Config build tsconfig must be a string when provided. */
197
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidBuildTsconfig"] = 3113] = "CliConfigInvalidBuildTsconfig";
198
- /** Config build bootstrap must be a string when provided. */
199
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidBuildBootstrap"] = 3114] = "CliConfigInvalidBuildBootstrap";
185
+ SeedcordErrorCode[SeedcordErrorCode["CliConfigMissingEntry"] = 3109] = "CliConfigMissingEntry";
200
186
  /** Entry file must be inside the configured root directory. */
201
- SeedcordErrorCode[SeedcordErrorCode["CliConfigEntryOutsideRoot"] = 3115] = "CliConfigEntryOutsideRoot";
187
+ SeedcordErrorCode[SeedcordErrorCode["CliConfigEntryOutsideRoot"] = 3110] = "CliConfigEntryOutsideRoot";
202
188
  /** Unable to locate a TypeScript config file for builds. */
203
- SeedcordErrorCode[SeedcordErrorCode["CliBuildTsconfigNotFound"] = 3116] = "CliBuildTsconfigNotFound";
189
+ SeedcordErrorCode[SeedcordErrorCode["CliBuildTsconfigNotFound"] = 3111] = "CliBuildTsconfigNotFound";
204
190
  /** TypeScript reported diagnostics during emit. */
205
- SeedcordErrorCode[SeedcordErrorCode["CliBuildFailed"] = 3117] = "CliBuildFailed";
191
+ SeedcordErrorCode[SeedcordErrorCode["CliBuildFailed"] = 3112] = "CliBuildFailed";
206
192
  /** Unable to write the generated bootstrap file. */
207
- SeedcordErrorCode[SeedcordErrorCode["CliBootstrapWriteFailed"] = 3118] = "CliBootstrapWriteFailed";
208
- /** Config hmr typecheck tsconfig must be a string when provided. */
209
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidTsconfig"] = 3119] = "CliConfigInvalidTsconfig";
210
- /** Config hmr options must be an object when provided. */
211
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidHmr"] = 3120] = "CliConfigInvalidHmr";
212
- /** Config hmr restart patterns must be an array of strings when provided. */
213
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidHmrRestart"] = 3121] = "CliConfigInvalidHmrRestart";
193
+ SeedcordErrorCode[SeedcordErrorCode["CliBootstrapWriteFailed"] = 3113] = "CliBootstrapWriteFailed";
214
194
  /** Two commands resolve to the same slash route during codegen. */
215
- SeedcordErrorCode[SeedcordErrorCode["CliCodegenDuplicateRoute"] = 3122] = "CliCodegenDuplicateRoute";
195
+ SeedcordErrorCode[SeedcordErrorCode["CliCodegenDuplicateRoute"] = 3114] = "CliCodegenDuplicateRoute";
216
196
  /** The commands directory could not be read during codegen. */
217
- SeedcordErrorCode[SeedcordErrorCode["CliCodegenCommandsDirUnreadable"] = 3123] = "CliCodegenCommandsDirUnreadable";
197
+ SeedcordErrorCode[SeedcordErrorCode["CliCodegenCommandsDirUnreadable"] = 3115] = "CliCodegenCommandsDirUnreadable";
218
198
  /** Two context-menu commands of the same kind share a name during codegen. */
219
- SeedcordErrorCode[SeedcordErrorCode["CliCodegenDuplicateContextMenu"] = 3124] = "CliCodegenDuplicateContextMenu";
199
+ SeedcordErrorCode[SeedcordErrorCode["CliCodegenDuplicateContextMenu"] = 3116] = "CliCodegenDuplicateContextMenu";
220
200
  /** Could not resolve the application from the bot token during `commands --clean`. */
221
- SeedcordErrorCode[SeedcordErrorCode["CliCleanAppFetchFailed"] = 3125] = "CliCleanAppFetchFailed";
201
+ SeedcordErrorCode[SeedcordErrorCode["CliCleanAppFetchFailed"] = 3117] = "CliCleanAppFetchFailed";
222
202
  /** `commands --clean` ran with neither --guild nor --all-guilds. */
223
- SeedcordErrorCode[SeedcordErrorCode["CliCleanNoGuilds"] = 3126] = "CliCleanNoGuilds";
203
+ SeedcordErrorCode[SeedcordErrorCode["CliCleanNoGuilds"] = 3118] = "CliCleanNoGuilds";
224
204
  /** `commands --clean` combined --purge with --all-guilds, which would wipe every guild. */
225
- SeedcordErrorCode[SeedcordErrorCode["CliCleanPurgeAllGuilds"] = 3127] = "CliCleanPurgeAllGuilds";
205
+ SeedcordErrorCode[SeedcordErrorCode["CliCleanPurgeAllGuilds"] = 3119] = "CliCleanPurgeAllGuilds";
226
206
  /** An interactive prompt was cancelled (Ctrl-C), so the command aborts without changes. */
227
- SeedcordErrorCode[SeedcordErrorCode["CliCancelled"] = 3128] = "CliCancelled";
207
+ SeedcordErrorCode[SeedcordErrorCode["CliCancelled"] = 3120] = "CliCancelled";
228
208
  /** `commands --clean --all-guilds` matched more guilds than the safety threshold without `--yes`. */
229
- SeedcordErrorCode[SeedcordErrorCode["CliCleanLargeBotUnconfirmed"] = 3129] = "CliCleanLargeBotUnconfirmed";
209
+ SeedcordErrorCode[SeedcordErrorCode["CliCleanLargeBotUnconfirmed"] = 3121] = "CliCleanLargeBotUnconfirmed";
230
210
  /** `commands --clean --apply` ran in a non-interactive environment without `--yes`, where it cannot prompt. */
231
- SeedcordErrorCode[SeedcordErrorCode["CliCleanApplyNeedsYes"] = 3130] = "CliCleanApplyNeedsYes";
232
- /** Config hmr rollback flag must be a boolean when provided. */
233
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidHmrRollback"] = 3131] = "CliConfigInvalidHmrRollback";
234
- /** Config tunnel must be a boolean or an https URL when provided. */
235
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidTunnel"] = 3132] = "CliConfigInvalidTunnel";
211
+ SeedcordErrorCode[SeedcordErrorCode["CliCleanApplyNeedsYes"] = 3122] = "CliCleanApplyNeedsYes";
236
212
  /** The cloudflared metrics server never reported a quick-tunnel hostname. */
237
- SeedcordErrorCode[SeedcordErrorCode["CliTunnelUrlUnavailable"] = 3133] = "CliTunnelUrlUnavailable";
213
+ SeedcordErrorCode[SeedcordErrorCode["CliTunnelUrlUnavailable"] = 3123] = "CliTunnelUrlUnavailable";
238
214
  /** Discord rejected the tunnel URL as an interactions endpoint. */
239
- SeedcordErrorCode[SeedcordErrorCode["CliTunnelNotVerified"] = 3134] = "CliTunnelNotVerified";
215
+ SeedcordErrorCode[SeedcordErrorCode["CliTunnelNotVerified"] = 3124] = "CliTunnelNotVerified";
240
216
  /** The tunnel URL never answered its health probe. */
241
- SeedcordErrorCode[SeedcordErrorCode["CliTunnelUnreachable"] = 3135] = "CliTunnelUnreachable";
242
- /** Config hmr typecheck flag must be a boolean or object when provided. */
243
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidHmrTypecheck"] = 3136] = "CliConfigInvalidHmrTypecheck";
244
- /** Config idleAnimation flag must be a boolean when provided. */
245
- SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidIdleAnimation"] = 3137] = "CliConfigInvalidIdleAnimation";
217
+ SeedcordErrorCode[SeedcordErrorCode["CliTunnelUnreachable"] = 3125] = "CliTunnelUnreachable";
218
+ /** A config field is present with the wrong shape. */
219
+ SeedcordErrorCode[SeedcordErrorCode["CliConfigInvalidField"] = 3126] = "CliConfigInvalidField";
246
220
  /** A create prompt was cancelled (Ctrl-C), and nothing has been written yet. */
247
221
  SeedcordErrorCode[SeedcordErrorCode["CreateCancelled"] = 3201] = "CreateCancelled";
248
222
  /** A flag supplied an answer for a question the earlier answers skip. */
@@ -258,18 +232,38 @@ let SeedcordErrorCode = /* @__PURE__ */ function(SeedcordErrorCode) {
258
232
  return SeedcordErrorCode;
259
233
  }({});
260
234
 
235
+ //#endregion
236
+ //#region src/palette.ts
237
+ const BRAND = {
238
+ flesh: "#f04e36",
239
+ rind: "#6fab49",
240
+ pith: "#f8f6e8"
241
+ };
242
+ const paint = {
243
+ sky: chalk.hex("#8fc7ff"),
244
+ iris: chalk.hex("#e29bff"),
245
+ mint: chalk.hex("#66d98a"),
246
+ amber: chalk.hex("#ffc061"),
247
+ coral: chalk.hex("#ff6b85"),
248
+ flesh: chalk.hex(BRAND.flesh),
249
+ rind: chalk.hex(BRAND.rind),
250
+ pith: chalk.hex(BRAND.pith),
251
+ mute: chalk.dim,
252
+ bold: chalk.bold,
253
+ italic: chalk.italic,
254
+ underline: chalk.underline
255
+ };
256
+
261
257
  //#endregion
262
258
  //#region src/ErrorMessages.ts
263
259
  /** @internal */
264
260
  const messages = {
265
- [1001]: () => "Missing DISCORD_BOT_TOKEN environment variable.",
266
- [1002]: () => "Invalid DISCORD_BOT_TOKEN value.",
267
- [1006]: () => "Missing DISCORD_PUBLIC_KEY environment variable.",
268
- [1007]: () => "Invalid DISCORD_PUBLIC_KEY value. Expected 64 hex characters.",
269
- [1008]: () => "The route manifest is generated by `seedcord build`. Run the build before importing it.",
270
- [1004]: (envKey) => `${envKey} is not a well-formed Discord webhook url.`,
271
- [1005]: (envKey) => `The webhook behind ${envKey} does not exist on Discord.`,
272
- [1003]: (count, failures) => `Could not resolve ${count} configured emoji${count === 1 ? "" : "s"} at startup.\n${failures}`,
261
+ [1005]: (name) => `Missing ${name} environment variable.`,
262
+ [1006]: (name, expected) => expected ? `Invalid ${name} value. Expected ${expected}.` : `Invalid ${name} value.`,
263
+ [1004]: () => "The route manifest is generated by `seedcord build`. Run the build before importing it.",
264
+ [1002]: (envKey) => `${envKey} is not a well-formed Discord webhook url.`,
265
+ [1003]: (envKey) => `The webhook behind ${envKey} does not exist on Discord.`,
266
+ [1001]: (count, failures) => `Could not resolve ${count} configured emoji${count === 1 ? "" : "s"} at startup.\n${failures}`,
273
267
  [1101]: () => "Cannot add tasks after startup sequence has already completed.",
274
268
  [1102]: () => "Cannot add tasks while startup sequence is in progress.",
275
269
  [1103]: () => "Cannot remove tasks while startup sequence is in progress.",
@@ -288,22 +282,21 @@ const messages = {
288
282
  [1209]: () => "The bot's application id could not be resolved.",
289
283
  [1210]: (accessor, key) => `${accessor}.${key} has no value yet. ${accessor} fills during startup, and a read at the top of a file runs before that.`,
290
284
  [1301]: () => "Interaction middleware cannot specify event filters.",
291
- [1302]: () => "Decorator could not locate the original method. Ensure the method exists before applying the decorator.",
292
- [1303]: (commandName, existingScope, requestedScope) => `Command "${commandName}" is already registered as a "${existingScope}" command and cannot be re-registered as a "${requestedScope}" command.`,
293
- [1304]: () => "RegisterCommand(\"global\") cannot have guilds specified.",
294
- [1305]: () => "RegisterCommand(\"guild\") requires a non-empty guilds array.",
295
- [1306]: () => "Middleware priority must be a finite number.",
296
- [1307]: (className) => `${className} extends WebhookLog and needs a @WebhookUrl decorator naming its env var.`,
285
+ [1302]: (commandName, existingScope, requestedScope) => `Command "${commandName}" is already registered as a "${existingScope}" command and cannot be re-registered as a "${requestedScope}" command.`,
286
+ [1303]: () => "RegisterCommand(\"global\") cannot have guilds specified.",
287
+ [1304]: () => "RegisterCommand(\"guild\") requires a non-empty guilds array.",
288
+ [1305]: () => "Middleware priority must be a finite number.",
289
+ [1306]: (className) => `${className} extends WebhookLog and needs a @WebhookUrl decorator naming its env var.`,
297
290
  [1401]: (route, first, second) => `Two interaction handlers resolve to the same route \`${route}\`. Registered by ${first} and ${second}. Rename one.`,
298
291
  [1402]: (name) => `Two different interaction middleware classes share the name \`${name}\`. Rename one so they do not collide.`,
299
292
  [1403]: (route, exportName, from) => `Route \`${route}\` loads \`${exportName}\` from ${from}, which exports no such name.`,
300
293
  [1404]: (keys, exportName, from) => `Subscriber row for \`${keys}\` loads \`${exportName}\` from ${from}, which does not extend Subscriber.`,
301
294
  [1405]: (route, from) => `Route \`${route}\` failed to import ${from}.`,
302
- [1501]: (method, reason, alternative, routeId) => `${chalk.cyan(`${method}()`)} was called when ${reason}.\n${alternative} (route ${chalk.cyan(routeId)})`,
303
- [1502]: (componentClass, index, detail, routeId) => `${chalk.cyan(componentClass)} at components[${index}] failed to serialize: ${detail.replace(/\.$/, "")}. (route ${chalk.cyan(routeId)})`,
304
- [1503]: (method, targetId, routeId) => `${chalk.cyan(`${method}()`)} was passed message ${targetId}, which this interaction did not send.\nPass a message this interaction sent, returned by reply(), followUp(), edit(), or update(). (route ${chalk.cyan(routeId)})`,
305
- [1504]: (method, routeId) => `${chalk.cyan(`${method}()`)} was called on a modal opened from a command, which has no source message.\nUse reply() or defer() instead. (route ${chalk.cyan(routeId)})`,
306
- [1505]: (method, routeId) => `The interaction callback for ${chalk.cyan(`${method}()`)} returned no message. (route ${chalk.cyan(routeId)})`,
295
+ [1501]: (method, reason, alternative, routeId) => `${paint.sky(`${method}()`)} was called when ${reason}.\n${alternative} (route ${paint.mute(routeId)})`,
296
+ [1502]: (componentClass, index, detail, routeId) => `${paint.sky(componentClass)} at components[${index}] failed to serialize: ${detail.replace(/\.$/, "")}. (route ${paint.mute(routeId)})`,
297
+ [1503]: (method, targetId, routeId) => `${paint.sky(`${method}()`)} was passed message ${targetId}, which this interaction did not send.\nPass a message this interaction sent, returned by reply(), followUp(), edit(), or update(). (route ${paint.mute(routeId)})`,
298
+ [1504]: (method, routeId) => `${paint.sky(`${method}()`)} was called on a modal opened from a command, which has no source message.\nUse reply() or defer() instead. (route ${paint.mute(routeId)})`,
299
+ [1505]: (method, routeId) => `The interaction callback for ${paint.sky(`${method}()`)} returned no message. (route ${paint.mute(routeId)})`,
307
300
  [1601]: (prefix) => `customId prefix ${JSON.stringify(prefix)} must be a non-empty string without a colon or control character.`,
308
301
  [1602]: (field) => `customId field name ${JSON.stringify(field)} is integer-like, which JS reorders. Use a non-numeric name.`,
309
302
  [1603]: (field) => `customId field ${JSON.stringify(field)} uses oneOf() with no choices.`,
@@ -326,6 +319,7 @@ const messages = {
326
319
  [1901]: (value) => `Cannot convert ${value} into a color.`,
327
320
  [1902]: () => "Color must be within the range 0 to 16777215 (0xffffff).",
328
321
  [2001]: (pluginName, reason) => `${pluginName} rejected its options, ${reason.replace(/\.$/, "")}.`,
322
+ [2002]: (count) => `${count} plugins failed to dispose.`,
329
323
  [2101]: (className) => `Missing @RegisterMongooseService on ${className}.`,
330
324
  [2102]: (databaseName) => databaseName ? `Could not connect to MongoDB (${databaseName}).` : "Could not connect to MongoDB.",
331
325
  [2103]: () => "Failed to disconnect from MongoDB cleanly during shutdown.",
@@ -346,41 +340,30 @@ const messages = {
346
340
  [2212]: (databaseName) => `Failed to ensure database ${databaseName} exists.`,
347
341
  [3101]: () => "Config file must default export an object.",
348
342
  [3102]: () => "Config must include an `instance` string that points to your Seedcord default export.",
349
- [3103]: () => "Config `root` must be a string when provided.",
350
- [3104]: (baseDir, candidates) => `Unable to locate a Seedcord config in ${baseDir}. Searched for ${candidates.join(", ")}.`,
351
- [3110]: () => "Config must include an `entry` string that points to your startup script.",
352
- [3111]: () => "Config `build` must be an object when provided.",
353
- [3112]: () => "Config `build.outDir` must be a string when provided.",
354
- [3113]: () => "Config `build.tsconfig` must be a string when provided.",
355
- [3114]: () => "Config `build.bootstrap` must be a string when provided.",
356
- [3115]: (entryPath, root) => `Entry file ${entryPath} must reside inside configured root ${root}.`,
357
- [3105]: (entryPath) => `Cannot find entry file at ${entryPath}.`,
358
- [3106]: (entryPath, reason) => `Failed to import ${entryPath} via tsx: ${reason}`,
359
- [3107]: (entryPath, nativeReason, fallbackReason) => `Failed to import ${entryPath}: ${nativeReason} (the jiti fallback also failed: ${fallbackReason})`,
360
- [3108]: () => "Seedcord instance must default export an object with a start() method.",
361
- [3109]: (instancePath, reason) => `Failed to start Seedcord from ${instancePath}: ${reason}`,
362
- [3116]: (hint) => `Unable to resolve a tsconfig for builds (${hint}). Provide build.tsconfig or add tsconfig.build.json / tsconfig.json.`,
363
- [3117]: (diagnostics) => `TypeScript build failed:\n${diagnostics}`,
364
- [3118]: (targetPath, reason) => `Failed to write bootstrap file at ${targetPath}: ${reason}`,
365
- [3119]: () => "Config `hmr.typecheck.tsconfig` must be a string when provided.",
366
- [3120]: () => "Config `hmr` must be an object when provided.",
367
- [3121]: () => "Config `hmr.restart` must be an array of strings when provided.",
368
- [3131]: () => "Config `hmr.rollback` must be a boolean when provided.",
369
- [3136]: () => "Config `hmr.typecheck` must be a boolean or an object when provided.",
370
- [3137]: () => "Config `idleAnimation` must be a boolean when provided.",
371
- [3122]: (route, firstFile, secondFile) => `Two commands resolve to the same slash route \`${route}\`. Defined in ${firstFile} and ${secondFile}. Rename one.`,
372
- [3123]: (dir, reason) => `Could not read the commands directory ${dir} during codegen. ${reason}`,
373
- [3124]: (kind, name, firstFile, secondFile) => `Two ${kind} context-menu commands share the name \`${name}\`. Defined in ${firstFile} and ${secondFile}. Rename one.`,
374
- [3125]: (reason) => `Could not resolve the application from the bot token. ${reason}`,
375
- [3126]: () => "No guilds given. Pass --guild <ids...> or --all-guilds. Global commands are never touched.",
376
- [3127]: () => "--purge cannot be combined with --all-guilds. Use --guild <ids> to purge specific guilds.",
377
- [3128]: () => "Cancelled.",
378
- [3129]: (count) => `Refusing to scan ${count} guilds without confirmation. Re-run with --yes, or name specific guilds with --guild <ids>.`,
379
- [3130]: () => "Refusing to delete without confirmation in a non-interactive environment. Re-run with --yes.",
380
- [3132]: () => "Config `tunnel` must be a boolean or an https URL.",
381
- [3133]: (seconds) => `cloudflared did not report a tunnel URL within ${seconds}s. Check that the binary runs and that the network allows it.`,
382
- [3134]: (url) => `Discord rejected ${url} as an interactions endpoint.`,
383
- [3135]: (url, seconds) => `${url} did not answer within ${seconds}s, so nothing was PATCHed to Discord.`,
343
+ [3103]: (baseDir, candidates) => `Unable to locate a Seedcord config in ${baseDir}. Searched for ${candidates.join(", ")}.`,
344
+ [3109]: () => "Config must include an `entry` string that points to your startup script.",
345
+ [3110]: (entryPath, root) => `Entry file ${entryPath} must reside inside configured root ${root}.`,
346
+ [3104]: (entryPath) => `Cannot find entry file at ${entryPath}.`,
347
+ [3105]: (entryPath, reason) => `Failed to import ${entryPath} via tsx: ${reason}`,
348
+ [3106]: (entryPath, nativeReason, fallbackReason) => `Failed to import ${entryPath}: ${nativeReason} (the jiti fallback also failed: ${fallbackReason})`,
349
+ [3107]: () => "Seedcord instance must default export an object with a start() method.",
350
+ [3108]: (instancePath, reason) => `Failed to start Seedcord from ${instancePath}: ${reason}`,
351
+ [3111]: (hint) => `Unable to resolve a tsconfig for builds (${hint}). Provide build.tsconfig or add tsconfig.build.json / tsconfig.json.`,
352
+ [3112]: (diagnostics) => `TypeScript build failed:\n${diagnostics}`,
353
+ [3113]: (targetPath, reason) => `Failed to write bootstrap file at ${targetPath}: ${reason}`,
354
+ [3114]: (route, firstFile, secondFile) => `Two commands resolve to the same slash route \`${route}\`. Defined in ${firstFile} and ${secondFile}. Rename one.`,
355
+ [3115]: (dir, reason) => `Could not read the commands directory ${dir} during codegen. ${reason}`,
356
+ [3116]: (kind, name, firstFile, secondFile) => `Two ${kind} context-menu commands share the name \`${name}\`. Defined in ${firstFile} and ${secondFile}. Rename one.`,
357
+ [3117]: (reason) => `Could not resolve the application from the bot token. ${reason}`,
358
+ [3118]: () => "No guilds given. Pass --guild <ids...> or --all-guilds. Global commands are never touched.",
359
+ [3119]: () => "--purge cannot be combined with --all-guilds. Use --guild <ids> to purge specific guilds.",
360
+ [3120]: () => "Cancelled.",
361
+ [3121]: (count) => `Refusing to scan ${count} guilds without confirmation. Re-run with --yes, or name specific guilds with --guild <ids>.`,
362
+ [3122]: () => "Refusing to delete without confirmation in a non-interactive environment. Re-run with --yes.",
363
+ [3123]: (seconds) => `cloudflared did not report a tunnel URL within ${seconds}s. Check that the binary runs and that the network allows it.`,
364
+ [3124]: (url) => `Discord rejected ${url} as an interactions endpoint.`,
365
+ [3125]: (url, seconds) => `${url} did not answer within ${seconds}s, so nothing was PATCHed to Discord.`,
366
+ [3126]: (field, expected) => `Config \`${field}\` must be ${expected} when provided.`,
384
367
  [3201]: () => "Cancelled.",
385
368
  [3202]: (flag) => `The --${flag} flag does not apply to the answers you gave.`,
386
369
  [3203]: (flag, reason) => `--${flag}: ${reason}`,
@@ -414,81 +397,96 @@ function resolveMessage(code, args) {
414
397
  return formatSeedcordErrorMessage(code, args);
415
398
  }
416
399
  function formatErrorName(name, _identifier, code) {
417
- return `${chalk.bold.red(name)}[${chalk.gray(code)}]`;
400
+ return `${paint.coral.bold(name)}[${paint.mute(code)}]`;
401
+ }
402
+ const kIdentifier = Symbol.for("seedcord.errors.identifier");
403
+ const CODED = Symbol.for("seedcord.errors.coded");
404
+ function brand(prototype) {
405
+ Object.defineProperty(prototype, CODED, { value: true });
406
+ }
407
+ function isCoded(error) {
408
+ return typeof error === "object" && error !== null && CODED in error;
418
409
  }
419
- /**
420
- * Base class for Seedcord errors.
421
- */
422
410
  var SeedcordError = class extends Error {
423
411
  code;
424
- identifier;
412
+ [kIdentifier];
425
413
  type = "SeedcordError";
426
414
  constructor(code, ...rest) {
427
415
  const { args, options } = resolveCtorInputs(rest);
428
416
  const message = resolveMessage(code, args);
429
417
  super(message, options);
430
418
  this.code = code;
431
- this.identifier = resolveIdentifier(code);
432
- this.name = formatErrorName(new.target.name, this.identifier, this.code);
419
+ this[kIdentifier] = resolveIdentifier(code);
420
+ this.name = formatErrorName(new.target.name, this[kIdentifier], this.code);
433
421
  Object.setPrototypeOf(this, new.target.prototype);
434
422
  if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, new.target);
435
423
  }
436
424
  };
437
- /**
438
- * TypeError class for Seedcord errors.
439
- */
425
+ brand(SeedcordError.prototype);
440
426
  var SeedcordTypeError = class extends TypeError {
441
427
  code;
442
- identifier;
428
+ [kIdentifier];
443
429
  type = "SeedcordTypeError";
444
430
  constructor(code, ...rest) {
445
431
  const { args, options } = resolveCtorInputs(rest);
446
432
  const message = resolveMessage(code, args);
447
433
  super(message, options);
448
434
  this.code = code;
449
- this.identifier = resolveIdentifier(code);
450
- this.name = formatErrorName(new.target.name, this.identifier, this.code);
435
+ this[kIdentifier] = resolveIdentifier(code);
436
+ this.name = formatErrorName(new.target.name, this[kIdentifier], this.code);
451
437
  Object.setPrototypeOf(this, new.target.prototype);
452
438
  if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, new.target);
453
439
  }
454
440
  };
455
- /**
456
- * RangeError class for Seedcord errors.
457
- */
441
+ brand(SeedcordTypeError.prototype);
458
442
  var SeedcordRangeError = class extends RangeError {
459
443
  code;
460
- identifier;
444
+ [kIdentifier];
461
445
  type = "SeedcordRangeError";
462
446
  constructor(code, ...rest) {
463
447
  const { args, options } = resolveCtorInputs(rest);
464
448
  const message = resolveMessage(code, args);
465
449
  super(message, options);
466
450
  this.code = code;
467
- this.identifier = resolveIdentifier(code);
468
- this.name = formatErrorName(new.target.name, this.identifier, this.code);
451
+ this[kIdentifier] = resolveIdentifier(code);
452
+ this.name = formatErrorName(new.target.name, this[kIdentifier], this.code);
453
+ Object.setPrototypeOf(this, new.target.prototype);
454
+ if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, new.target);
455
+ }
456
+ };
457
+ brand(SeedcordRangeError.prototype);
458
+ var SeedcordAggregateError = class extends AggregateError {
459
+ code;
460
+ [kIdentifier];
461
+ type = "SeedcordAggregateError";
462
+ constructor(code, errors, ...rest) {
463
+ const { args, options } = resolveCtorInputs(rest);
464
+ const message = resolveMessage(code, args);
465
+ super(errors, message, options);
466
+ this.code = code;
467
+ this[kIdentifier] = resolveIdentifier(code);
468
+ this.name = formatErrorName(new.target.name, this[kIdentifier], this.code);
469
469
  Object.setPrototypeOf(this, new.target.prototype);
470
470
  if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, new.target);
471
471
  }
472
472
  };
473
+ brand(SeedcordAggregateError.prototype);
473
474
  /**
474
475
  * Determines whether an unknown value is a Seedcord error, with optional narrowing by class and error code.
475
476
  *
476
477
  * @param error - The value to inspect.
477
- * @param type - Optional error class discriminator (Error, TypeError, or RangeError).
478
+ * @param type - Optional error class discriminator.
478
479
  * @param code - Optional {@link SeedcordErrorCode} discriminator to narrow by code.
479
480
  * @typeParam Type - What kind of {@link SeedcordErrorTypeString} to filter by.
480
481
  * @typeParam Code - The specific {@link SeedcordErrorCode} to filter by.
481
482
  */
482
483
  function isSeedcordError(error, type, code) {
483
- const isSeedcordErrorInstance = error instanceof SeedcordError && error.type === "SeedcordError";
484
- const isSeedcordTypeErrorInstance = error instanceof SeedcordTypeError && error.type === "SeedcordTypeError";
485
- const isSeedcordRangeErrorInstance = error instanceof SeedcordRangeError && error.type === "SeedcordRangeError";
486
- if (!isSeedcordErrorInstance && !isSeedcordTypeErrorInstance && !isSeedcordRangeErrorInstance) return false;
487
- if (!(type ? type === "SeedcordError" && isSeedcordErrorInstance || type === "SeedcordTypeError" && isSeedcordTypeErrorInstance || type === "SeedcordRangeError" && isSeedcordRangeErrorInstance : true)) return false;
484
+ if (!isCoded(error)) return false;
485
+ if (type && error.type !== type) return false;
488
486
  if (code === void 0) return true;
489
- return error.code === code;
487
+ return error[kIdentifier] === resolveIdentifier(code);
490
488
  }
491
489
 
492
490
  //#endregion
493
- export { SeedcordErrorCode as a, isSeedcordError as i, SeedcordRangeError as n, SeedcordTypeError as r, SeedcordError as t };
494
- //# sourceMappingURL=SeedcordError-B5hcAoT3.mjs.map
491
+ export { isSeedcordError as a, SeedcordErrorCode as c, SeedcordTypeError as i, SeedcordError as n, BRAND as o, SeedcordRangeError as r, paint as s, SeedcordAggregateError as t };
492
+ //# sourceMappingURL=SeedcordError-BLQ8_el7.mjs.map