# ComponentEmbedError

`class` in `discord-component-embed` · v1.0.0

<https://seedcord.org/docs/packages/discord-component-embed/1.0.0/classes/component-embed-error>

Thrown when a component tree breaks a rule of Discord's component embed format, or when your own code throws while
the package reads the tree. Read [`code`](/docs/packages/discord-component-embed/1.0.0/classes/component-embed-error#code) to tell which. Discord doesn't report an invalid
payload. It shows the Open Graph card, or no preview at all for most payloads that break Discord's general component
rules, like a bad `id`.

```ts
class ComponentEmbedError extends Error
```

## Examples

```ts
try {
    toComponentEmbed(<GuidePreview page={page} />);
} catch (error) {
    if (error instanceof ComponentEmbedError && error.code === 'ReadFailed') console.error(error.cause);
    throw error;
}
```

## Constructors

### constructor

```ts
ComponentEmbedError(
    code: ComponentEmbedErrorCode,
    message: string,
    { path, ...options }?,
    input?: ErrorOptions & { path?: readonly string[] }
)
```

Constructs a new instance of the `ComponentEmbedError` class

## Properties

### code

```ts
public readonly code: ComponentEmbedErrorCode
```

Which rule the tree broke.

### name

```ts
public readonly name
```

### path

```ts
public readonly path: readonly string[]
```

The steps from the root to the component that broke a rule, like `['Container', 'PostCard', 'Section 2']`. Your
own components appear by name. A number marks a component written next to others with the same name. The path
is empty when the problem is the whole embed, like its size. For a tree from [`fromPayload`](/docs/packages/discord-component-embed/1.0.0/functions/from-payload), the steps are
JSON keys and array indexes counted from 0, like `['component', 'components', '1']`.
