# CompactError

> For the complete documentation index, see [llms.txt](https://docs.midnight.network/llms.txt)

[**@midnight-ntwrk/compact-runtime v0.21.0**](https://docs.midnight.network/api-reference/compact-runtime.md)

***

[@midnight-ntwrk/compact-runtime](https://docs.midnight.network/api-reference/compact-runtime/globals.md) / CompactError

# Class: CompactError

An error originating from code generated by the Compact compiler

## Extends[​](#extends "Direct link to Extends")

* `Error`

## Extended by[​](#extended-by "Direct link to Extended by")

## Constructors[​](#constructors "Direct link to Constructors")

### Constructor[​](#constructor "Direct link to Constructor")

```
new CompactError(msg): CompactError;
```

#### Parameters[​](#parameters "Direct link to Parameters")

##### msg[​](#msg "Direct link to msg")

`string`

#### Returns[​](#returns "Direct link to Returns")

`CompactError`

#### Overrides[​](#overrides "Direct link to Overrides")

```
Error.constructor
```

## Properties[​](#properties "Direct link to Properties")

### cause?[​](#cause "Direct link to cause?")

```
optional cause: unknown;
```

#### Inherited from[​](#inherited-from "Direct link to Inherited from")

```
Error.cause
```

***

### isCompactError[​](#iscompacterror "Direct link to isCompactError")

```
readonly isCompactError: true = true;
```

***

### message[​](#message "Direct link to message")

```
message: string;
```

#### Inherited from[​](#inherited-from-1 "Direct link to Inherited from")

```
Error.message
```

***

### name[​](#name "Direct link to name")

```
name: string;
```

#### Inherited from[​](#inherited-from-2 "Direct link to Inherited from")

```
Error.name
```

***

### stack?[​](#stack "Direct link to stack?")

```
optional stack: string;
```

#### Inherited from[​](#inherited-from-3 "Direct link to Inherited from")

```
Error.stack
```

***

### stackTraceLimit[​](#stacktracelimit "Direct link to stackTraceLimit")

```
static stackTraceLimit: number;
```

The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`).

The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

#### Inherited from[​](#inherited-from-4 "Direct link to Inherited from")

```
Error.stackTraceLimit
```

## Methods[​](#methods "Direct link to Methods")

### captureStackTrace()[​](#capturestacktrace "Direct link to captureStackTrace()")

```
static captureStackTrace(targetObject, constructorOpt?): void;
```

Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called.

```
const myObject = {};

Error.captureStackTrace(myObject);

myObject.stack;  // Similar to `new Error().stack`
```

The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`.

The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace.

The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance:

```
function a() {

  b();

}



function b() {

  c();

}



function c() {

  // Create an error without stack trace to avoid calculating the stack trace twice.

  const { stackTraceLimit } = Error;

  Error.stackTraceLimit = 0;

  const error = new Error();

  Error.stackTraceLimit = stackTraceLimit;



  // Capture the stack trace above function b

  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace

  throw error;

}



a();
```

#### Parameters[​](#parameters-1 "Direct link to Parameters")

##### targetObject[​](#targetobject "Direct link to targetObject")

`object`

##### constructorOpt?[​](#constructoropt "Direct link to constructorOpt?")

`Function`

#### Returns[​](#returns-1 "Direct link to Returns")

`void`

#### Inherited from[​](#inherited-from-5 "Direct link to Inherited from")

```
Error.captureStackTrace
```

***

### is()[​](#is "Direct link to is()")

```
static is(u): u is CompactError;
```

Recognizes instances across copies of this package, subclasses included, where `instanceof` would not: a generated contract module resolves the runtime from its own location, so the copy that throws is not the copy an application catches with.

#### Parameters[​](#parameters-2 "Direct link to Parameters")

##### u[​](#u "Direct link to u")

`unknown`

#### Returns[​](#returns-2 "Direct link to Returns")

`u is CompactError`

***

### prepareStackTrace()[​](#preparestacktrace "Direct link to prepareStackTrace()")

```
static prepareStackTrace(err, stackTraces): any;
```

#### Parameters[​](#parameters-3 "Direct link to Parameters")

##### err[​](#err "Direct link to err")

`Error`

##### stackTraces[​](#stacktraces "Direct link to stackTraces")

`CallSite`\[]

#### Returns[​](#returns-3 "Direct link to Returns")

`any`

#### See[​](#see "Direct link to See")

<https://v8.dev/docs/stack-trace-api#customizing-stack-traces>

#### Inherited from[​](#inherited-from-6 "Direct link to Inherited from")

```
Error.prepareStackTrace
```
