> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# Class: ToolNotFoundError

在函数映射形式的 ToolProvider 中找不到工具名称时抛出的标准错误。Renderer 在内联规范化时用它给出清晰的错误信息。

## Extends

- `Error`

## Constructors

### Constructor

> **new ToolNotFoundError**(`toolName`: `string`, `availableTools?`: `string`\[]): `ToolNotFoundError`

#### Parameters

| Parameter         | Type        |
| ----------------- | ----------- |
| `toolName`        | `string`    |
| `availableTools?` | `string`\[] |

#### Returns

`ToolNotFoundError`

#### Overrides

`Error.constructor`

## Properties

### availableTools

> `readonly` **availableTools**: `string`\[]

***

### cause?

> `optional` **cause?**: `unknown`

#### Inherited from

`Error.cause`

***

### message

> **message**: `string`

#### Inherited from

`Error.message`

***

### name

> **name**: `string`

#### Inherited from

`Error.name`

***

### stack?

> `optional` **stack?**: `string`

#### Inherited from

`Error.stack`

***

### toolName

> `readonly` **toolName**: `string`

***

### stackTraceLimit

> `static` **stackTraceLimit**: `number`

`Error.stackTraceLimit` 属性指定堆栈跟踪收集的栈帧数量（无论是通过 `new Error().stack` 还是 `Error.captureStackTrace(obj)` 生成）。

默认值为 `10`，可以设置为任意有效的 JavaScript 数字。修改后只影响之后捕获的堆栈跟踪。

如果设置为非数字或负数，堆栈跟踪将不会捕获任何栈帧。

#### Inherited from

`Error.stackTraceLimit`

## Methods

### captureStackTrace()

> `static` **captureStackTrace**(`targetObject`: `object`, `constructorOpt?`: `Function`): `void`

在 `targetObject` 上创建 `.stack` 属性，访问时返回一个字符串，表示调用 `Error.captureStackTrace()` 时所在的代码位置。

```js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`
```

堆栈跟踪的第一行会以 `${myObject.name}: ${myObject.message}` 作为前缀。

可选参数 `constructorOpt` 接受一个函数。如果传入，生成的堆栈跟踪会省略 `constructorOpt` 及其之上的所有栈帧。

`constructorOpt` 参数可以向用户隐藏生成错误的实现细节。例如：

```js
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

| Parameter         | Type       |
| ----------------- | ---------- |
| `targetObject`    | `object`   |
| `constructorOpt?` | `Function` |

#### Returns

`void`

#### Inherited from

`Error.captureStackTrace`

***

### isError()

> `static` **isError**(`error`: `unknown`): `error is Error`

判断传入的参数是否为内置的 Error 实例。

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `error`   | `unknown` |

#### Returns

`error is Error`

#### Inherited from

`Error.isError`

***

### prepareStackTrace()

> `static` **prepareStackTrace**(`err`: `Error`, `stackTraces`: `CallSite`\[]): `any`

#### Parameters

| Parameter     | Type          |
| ------------- | ------------- |
| `err`         | `Error`       |
| `stackTraces` | `CallSite`\[] |

#### Returns

`any`

#### See

[https://v8.dev/docs/stack-trace-api#customizing-stack-traces](https://v8.dev/docs/stack-trace-api#customizing-stack-traces)

#### Inherited from

`Error.prepareStackTrace`
