@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
1 lines • 2.09 kB
Source Map (JSON)
{"version":3,"sources":["../../../../src/lib/errors/UserError.ts"],"names":[],"mappings":";;;AAYO,IAAM,UAAA,GAAN,MAAM,UAAA,SAAkB,KAAM,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAe7B,YAAY,OAA4B,EAAA;AAC9C,IAAA,KAAA,CAAM,QAAQ,OAAO,CAAA;AACrB,IAAA,IAAA,CAAK,aAAa,OAAQ,CAAA,UAAA;AAC1B,IAAK,IAAA,CAAA,OAAA,GAAU,QAAQ,OAAW,IAAA,IAAA;AAAA;AACnC;AAAA,EAGA,IAAoB,IAAe,GAAA;AAClC,IAAO,OAAA,WAAA;AAAA;AAET,CAAA;AAzBqC,MAAA,CAAA,UAAA,EAAA,WAAA,CAAA;AAA9B,IAAM,SAAN,GAAA","file":"UserError.mjs","sourcesContent":["/**\n * The UserError class to be emitted in the pieces.\n * @property name This will be `'UserError'` and can be used to distinguish the type of error when any error gets thrown\n * @example\n * ```typescript\n * throw new UserError({\n * identifier: 'AddArgumentError',\n * message: 'You must write two numbers, but the second one did not match.',\n * context: { received: 2, expected: 3 }\n * });\n * ```\n */\nexport class UserError extends Error {\n\t/**\n\t * An identifier, useful to localize emitted errors.\n\t */\n\tpublic readonly identifier: string;\n\n\t/**\n\t * User-provided context.\n\t */\n\tpublic readonly context: unknown;\n\n\t/**\n\t * Constructs an UserError.\n\t * @param options The UserError options\n\t */\n\tpublic constructor(options: UserError.Options) {\n\t\tsuper(options.message);\n\t\tthis.identifier = options.identifier;\n\t\tthis.context = options.context ?? null;\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/class-literal-property-style\n\tpublic override get name(): string {\n\t\treturn 'UserError';\n\t}\n}\n\nexport namespace UserError {\n\t/**\n\t * The options for {@link UserError}.\n\t * @since 1.0.0\n\t */\n\texport interface Options {\n\t\t/**\n\t\t * The identifier for this error.\n\t\t * @since 1.0.0\n\t\t */\n\t\tidentifier: string;\n\n\t\t/**\n\t\t * The message to be passed to the Error constructor.\n\t\t * @since 1.0.0\n\t\t */\n\t\tmessage?: string;\n\n\t\t/**\n\t\t * The extra context to provide more information about this error.\n\t\t * @since 1.0.0\n\t\t * @default null\n\t\t */\n\t\tcontext?: unknown;\n\t}\n}\n"]}