Mongster

Errors

The error types Mongster uses for validation, queries, and runtime failures

All Mongster errors inherit from MongsterError. The specialized classes let you handle failures at the right level without pattern-matching raw strings.

import { ,  } from "mongster";

try {
  throw new ("Email is required");
} catch () {
  if ( instanceof ) {
    .(.);
  }

  if ( instanceof ) {
    .(., .);
  }
}

Error classes

ErrorTypical cause
SchemaErrorInvalid input for a schema field
ValidationErrorInvalid update operators or schema validation failure
QueryErrorInvalid query builder usage or populate / aggregation misuse
ConnectionErrorMissing URI or failed database connection
TransactionErrorA transaction callback failed or the session could not complete
IndexSyncErrorIndex normalization or syncing failed

When to catch what

  • Catch ValidationError when you want to return a user-facing input error.
  • Catch ConnectionError during startup and fail fast.
  • Catch MongsterError when you want one fallback for every library-specific failure.

On this page