AIDK API Reference / aidk-shared / StateError
Class: StateError ​
Defined in: packages/shared/src/errors.ts:381
Error thrown when an operation is attempted in an invalid state.
Example ​
typescript
throw new StateError('streaming', 'completed', 'Cannot send message to completed execution');
throw new StateError('initializing', 'ready', 'Engine is still initializing');Extends ​
Constructors ​
Constructor ​
ts
new StateError(
current: string,
expectedState: string | undefined,
message: string,
code:
| "STATE_INVALID"
| "STATE_TRANSITION"
| "STATE_NOT_READY"
| "STATE_ALREADY_COMPLETE",
cause?: Error): StateError;Defined in: packages/shared/src/errors.ts:388
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
current | string | undefined |
expectedState | string | undefined | undefined |
message | string | undefined |
code | | "STATE_INVALID" | "STATE_TRANSITION" | "STATE_NOT_READY" | "STATE_ALREADY_COMPLETE" | "STATE_INVALID" |
cause? | Error | undefined |
Returns ​
StateError
Overrides ​
Properties ​
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
code | readonly | AIDKErrorCode | Unique error code for programmatic handling | AIDKError.code | packages/shared/src/errors.ts:100 |
current | readonly | string | Current state | - | packages/shared/src/errors.ts:383 |
details | readonly | Record<string, unknown> | Additional error details | AIDKError.details | packages/shared/src/errors.ts:103 |
expectedState? | readonly | string | Expected/required state (optional) | - | packages/shared/src/errors.ts:386 |
Methods ​
alreadyComplete() ​
ts
static alreadyComplete(operation: string): StateError;Defined in: packages/shared/src/errors.ts:420
Create error for "already complete" state
Parameters ​
| Parameter | Type |
|---|---|
operation | string |
Returns ​
StateError
fromJSON() ​
ts
static fromJSON(json: SerializedAIDKError): AIDKError;Defined in: packages/shared/src/errors.ts:163
Create error from serialized format
Parameters ​
| Parameter | Type |
|---|---|
json | SerializedAIDKError |
Returns ​
Inherited from ​
notReady() ​
ts
static notReady(component: string, current: string): StateError;Defined in: packages/shared/src/errors.ts:408
Create error for "not ready" state
Parameters ​
| Parameter | Type |
|---|---|
component | string |
current | string |
Returns ​
StateError
toJSON() ​
ts
toJSON(): SerializedAIDKError;Defined in: packages/shared/src/errors.ts:131
Serialize error for transport (JSON-safe)