Skip to content
GitHub

isExplainedError

function in meocord/common Since 4.1.0

isExplainedError(error: unknown): boolean

Whether MeoCord has already logged what went wrong and what to do about it.

Use it where a bot logs a startup failure, so an error MeoCord explained is not logged twice: an app MeoCordFactory.create() refuses, such as two handlers for one command, or Discord refusing the bot token or a privileged intent at login. The error is otherwise unchanged.

Parameters

NameTypeDescription
errorunknown

An error MeoCordFactory.create() threw or app.start() rejected with.

Returns

boolean

true when MeoCord explained the error.

Examples

TypeScript
// src/main.ts, as a generated app has it
declare const App: new () => object
const logger = new Logger()

async function bootstrap() {
  const app = MeoCordFactory.create(App)
  await app.start()
}

// An error MeoCord explained, such as an app it refuses or a token Discord refused, is already logged
bootstrap().catch(error => {
  if (!isExplainedError(error)) logger.error('Error during startup:', error)
  process.exitCode = 1
})