Skip to content

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 ​

ParameterTypeDefault value
currentstringundefined
expectedStatestring | undefinedundefined
messagestringundefined
code| "STATE_INVALID" | "STATE_TRANSITION" | "STATE_NOT_READY" | "STATE_ALREADY_COMPLETE""STATE_INVALID"
cause?Errorundefined

Returns ​

StateError

Overrides ​

AIDKError.constructor

Properties ​

PropertyModifierTypeDescriptionInherited fromDefined in
codereadonlyAIDKErrorCodeUnique error code for programmatic handlingAIDKError.codepackages/shared/src/errors.ts:100
currentreadonlystringCurrent state-packages/shared/src/errors.ts:383
detailsreadonlyRecord<string, unknown>Additional error detailsAIDKError.detailspackages/shared/src/errors.ts:103
expectedState?readonlystringExpected/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 ​

ParameterType
operationstring

Returns ​

StateError


fromJSON() ​

ts
static fromJSON(json: SerializedAIDKError): AIDKError;

Defined in: packages/shared/src/errors.ts:163

Create error from serialized format

Parameters ​

ParameterType
jsonSerializedAIDKError

Returns ​

AIDKError

Inherited from ​

AIDKError.fromJSON


notReady() ​

ts
static notReady(component: string, current: string): StateError;

Defined in: packages/shared/src/errors.ts:408

Create error for "not ready" state

Parameters ​

ParameterType
componentstring
currentstring

Returns ​

StateError


toJSON() ​

ts
toJSON(): SerializedAIDKError;

Defined in: packages/shared/src/errors.ts:131

Serialize error for transport (JSON-safe)

Returns ​

SerializedAIDKError

Inherited from ​

AIDKError.toJSON

Released under the MIT License.