Skip to content

InvalidDecoratorItemException

reference
1 min readUpdated

Kind: Class

Source: packages/common/utils/validate-each.util.ts

Part of: Common

InvalidDecoratorItemException represents an invalid item encountered while validating decorator metadata or decorator-provided collections. It provides a what() method that returns a human-readable diagnostic message, allowing validation and tooling code to report the failure consistently.

Extends: Error

Methods

MethodSignatureReturns
whatwhat()string

Diagram

mermaid
graph LR
  A[Decorator metadata validation] --> B[Invalid decorator item detected]
  B --> C[InvalidDecoratorItemException]
  C --> D[what(): string]
  D --> E[Readable diagnostic message]

Usage

ts
import { InvalidDecoratorItemException } from '@nestjs/common';

try {
  // Run code that processes or validates decorator metadata.
  initializeApplicationMetadata();
} catch (error) {
  if (error instanceof InvalidDecoratorItemException) {
    console.error(`Decorator configuration error: ${error.what()}`);
  }

  throw error;
}

AI Coding Instructions

  • Use InvalidDecoratorItemException for invalid decorator items rather than throwing generic Error instances.
  • Call what() when presenting the error in logs, diagnostics, or developer-facing validation output.
  • Preserve the original exception when catching it; avoid replacing it with a less specific error type.
  • Keep decorator validation failures actionable by ensuring invalid items can be identified by the surrounding validation logic.

Was this page helpful?

Download as PDF
InvalidDecoratorItemException — NestJS head-to-head