---
title: "ValidationError: class in Diagnostics, TypeShade API"
description: "ValidationError, a class in Diagnostics. Thrown by validate when a module fails one of the structural rules every emit depends on."
url: https://typeshade.dev/api/validationerror/
language: en
---

# `ValidationError`

Class in Diagnostics

Thrown by validate when a module fails one of the structural rules every emit depends on.

`import { ValidationError } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
class ValidationError extends TypeShadeError
```

## Description

Subclasses [`TypeShadeError`](https://typeshade.dev/api/typeshadeerror/) and carries code [`SD0020`](https://typeshade.dev/reference/errors/sd0020/), so an `instanceof TypeShadeError` handler catches it and a handler that switches on `code` routes it.

Catch this class for [`ValidationError.diagnostics`](https://typeshade.dev/api/validationerror/): `validate()` collects every error-severity diagnostic before throwing, so one throw reports every failure in the module. `.message` renders the same list as text; the array is the form to present in a UI or a test report.

## Examples

### Example

```ts
import { validate, ValidationError } from 'typeshade'

try {
  validate(MODULE)
} catch (e) {
  if (e instanceof ValidationError) for (const d of e.diagnostics) report(d.ruleId, d.message)
  else throw e
}
```

## Constructor

**`new ValidationError(diags: readonly Diagnostic[])`**

## Instance properties

**`diagnostics` read only `readonly Diagnostic[]`**

Every error-severity diagnostic that caused the failure, in the order the rules reported them.

## In the guide

- [Diagnostics](https://typeshade.dev/guide/internals/diagnostics/)

## See also

- [`validate`](https://typeshade.dev/api/validate/)
- [`TypeShadeError`](https://typeshade.dev/api/typeshadeerror/)

## Source

[`src/core/passes/validate.ts`, line 59](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/validate.ts#L59), at commit af54ddad5
