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
| Method | Signature | Returns |
|---|---|---|
what | what() | string |
Diagram
mermaidgraph LR A[Decorator metadata validation] --> B[Invalid decorator item detected] B --> C[InvalidDecoratorItemException] C --> D[what(): string] D --> E[Readable diagnostic message]
Usage
tsimport { 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
InvalidDecoratorItemExceptionfor invalid decorator items rather than throwing genericErrorinstances. - 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?