# EnvaptError

The error envapt throws. Its `code` identifies the failure.

## Example

```ts
try {
  Envapter.require('DATABASE_URL', 'SESSION_SECRET');
} catch (error) {
  if (error instanceof EnvaptError && error.code === EnvaptErrorCodes.MissingEnvValue) {
    console.error(error.message);
    process.exit(1);
  }
  throw error;
}
```

## See

[https://envapt.materwelon.dev/docs/errors#the-error-shape](https://envapt.materwelon.dev/docs/errors#the-error-shape)

## Extends

- `Error`

## Constructors

### Constructor

```ts
new EnvaptError(
   code, 
   message, 
   options?
): EnvaptError;
```

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `code` | [`EnvaptErrorCodes`](../type-aliases/EnvaptErrorCodes.mdx) |
| `message` | `string` |
| `options?` | `EnvaptErrorOptions` |

#### Returns

`EnvaptError`

#### Overrides

```ts
Error.constructor
```

## Properties

| Property | Modifier | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ | ------ |
|  `cause?` | `public` | `unknown` | - | `Error.cause` |
|  `code` | `readonly` | [`EnvaptErrorCodes`](../type-aliases/EnvaptErrorCodes.mdx) | The [EnvaptErrorCodes](../variables/EnvaptErrorCodes.mdx) value identifying what failed. | - |
|  `issues` | `readonly` | readonly [`EnvaptIssue`](../interfaces/EnvaptIssue.mdx)[] \| `undefined` | Populated only for [EnvaptErrorCodes.SchemaValidationFailed](../variables/EnvaptErrorCodes.mdx#property-schemavalidationfailed) (208) and [EnvaptErrorCodes.InvalidEnvValue](../variables/EnvaptErrorCodes.mdx#property-invalidenvvalue) (210). For every other code this is `undefined`. If a custom parser or schema throws during a required read, the issue for that key keeps the thrown value as `cause`. If exactly one issue has a `cause`, the error's own `cause` is that value too. | - |
|  `message` | `public` | `string` | - | `Error.message` |
|  `name` | `public` | `string` | - | `Error.name` |
|  `stack?` | `public` | `string` | - | `Error.stack` |