errors: typed helpers for every documented error type

AlexaErrors has a helper for each of the 73 types of the table on
alexa-errorresponse.html, named after the type in camel case: 63 take the
message only, 10 take the payload fields their page documents. A field the
page requires (reason, currentDeviceMode, currentChargeState, resourceType)
is a required argument, so leaving it out does not compile; from JavaScript
the helper throws a TypeError that lists the values. validRange is optional,
as the page says, and has both ends when given.
temperatureOutOfRange and setpointsTooClose stay as shorter names.
The helpers are compared with the 15 examples of the four error pages.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
David 2026-09-28 21:14:55 +00:00
parent 4a3dd81bcf
commit 94b13f733a
36 changed files with 874 additions and 138 deletions

View file

@ -1,3 +1,4 @@
import type { ErrorType } from "../registry/catalog.js";
import type { Temperature } from "../registry/schema.js";
/**
* The namespace an ErrorResponse of this type goes under: the one the table of error types lists it with
@ -17,36 +18,145 @@ export declare class AlexaError extends Error {
readonly namespace: string;
constructor(type: string, message: string, extra?: Record<string, unknown>, namespace?: string);
}
export type CurrentDeviceMode = "ASLEEP" | "COLOR" | "DEMAND_RESPONSE" | "ECO" | "NOT_PROVISIONED" | "VACATION" | "OTHER";
export type ControlUnavailableReason = "DEEP_SLEEP_MODE" | "OUT_OF_NETWORK_CONNECTIVITY" | "NO_CONNECTIVITY_PACKAGE_ENABLED" | "UNKNOWN";
export type ChargeState = "ALREADY_CHARGED_TO_REQUIRED_LEVEL" | "CURRENTLY_CHARGING" | "FULLY_CHARGED" | "NOT_CONNECTED_TO_POWER";
export declare const AlexaErrors: {
/** An error of any type. */
of(type: string, message: string, extra?: Record<string, unknown>): AlexaError;
/** The value is outside what the endpoint takes. For a temperature: temperatureOutOfRange(). */
valueOutOfRange(message: string, validRange: {
minimumValue: number;
maximumValue: number;
}): AlexaError;
temperatureOutOfRange(message: string, validRange: {
minimumValue: Temperature;
maximumValue: Temperature;
}): AlexaError;
declare const CURRENT_DEVICE_MODES: readonly ["ASLEEP", "COLOR", "DEMAND_RESPONSE", "ECO", "NOT_PROVISIONED", "VACATION", "OTHER"];
declare const REASONS: readonly ["DEEP_SLEEP_MODE", "OUT_OF_NETWORK_CONNECTIVITY", "NO_CONNECTIVITY_PACKAGE_ENABLED", "UNKNOWN"];
declare const CHARGE_STATES: readonly ["ALREADY_CHARGED_TO_REQUIRED_LEVEL", "CURRENTLY_CHARGING", "FULLY_CHARGED", "NOT_CONNECTED_TO_POWER"];
declare const RESOURCE_TYPES: readonly ["WATER"];
declare const MAINTENANCE_ACTIONS: readonly ["EMPTY_BIN"];
export type CurrentDeviceMode = (typeof CURRENT_DEVICE_MODES)[number];
export type ControlUnavailableReason = (typeof REASONS)[number];
export type ChargeState = (typeof CHARGE_STATES)[number];
export type ResourceType = (typeof RESOURCE_TYPES)[number];
export type MaintenanceAction = (typeof MAINTENANCE_ACTIONS)[number];
/** The acceptable values of a setting: both ends, as numbers or as temperatures. */
export interface ValidRange<T> {
minimumValue: T;
maximumValue: T;
}
/** A sensor that is open while the panel is armed: Alexa says the name, and bypasses the ones with an endpointId. */
export interface EndpointNeedingBypass {
friendlyName: string;
endpointId?: string;
}
declare const withFields: {
/** The value is outside what the endpoint takes. For a temperature: temperatureValueOutOfRange(). */
valueOutOfRange(message: string, validRange?: ValidRange<number>): AlexaError;
temperatureValueOutOfRange(message: string, validRange?: ValidRange<Temperature>): AlexaError;
/** A light showing a color asked for a color temperature: "COLOR". */
notSupportedInCurrentMode(message: string, currentDeviceMode: CurrentDeviceMode): AlexaError;
/** percentageState: what is left of the battery, 0 to 100. */
endpointLowPower(message: string, percentageState?: number): AlexaError;
endpointControlUnavailable(message: string, reason: ControlUnavailableReason): AlexaError;
/** currentChargeLevelInPercentage: the battery level, 0 to 100. */
notSupportedWithCurrentBatteryChargeState(message: string, currentChargeState: ChargeState, currentChargeLevelInPercentage?: number): AlexaError;
/** What has to be refilled. */
insufficientResource(message: string, resourceType: "WATER"): AlexaError;
insufficientResource(message: string, resourceType: ResourceType): AlexaError;
/** What the user has to do first. */
maintenanceRequired(message: string, maintenanceAction?: "EMPTY_BIN"): AlexaError;
maintenanceRequired(message: string, maintenanceAction?: MaintenanceAction): AlexaError;
/** Goes under Alexa.ThermostatController. minimumTemperatureDelta: how far apart the setpoints have to be. */
setpointsTooClose(message: string, minimumTemperatureDelta?: Temperature): AlexaError;
requestedSetpointsTooClose(message: string, minimumTemperatureDelta?: Temperature): AlexaError;
/** Goes under Alexa.SecurityPanelController. With the endpoints listed, the user can bypass them by voice. */
bypassNeeded(message: string, endpointsNeedingBypass?: Array<{
friendlyName: string;
endpointId?: string;
}>): AlexaError;
bypassNeeded(message: string, endpointsNeedingBypass?: EndpointNeedingBypass[]): AlexaError;
};
type CamelCase<S extends string> = S extends `${infer First}_${infer Rest}` ? `${Lowercase<First>}${Capitalize<CamelCase<Rest>>}` : Lowercase<S>;
/** The helpers of the types whose payload is the type and the message: AlexaErrors.endpointUnreachable(message). */
export type PlainErrorHelpers = {
[T in ErrorType as CamelCase<T> extends keyof typeof withFields ? never : CamelCase<T>]: (message: string) => AlexaError;
};
/**
* An error for every type of the table of alexa-errorresponse.html, under the name of the type in camel case:
*
* throw AlexaErrors.endpointUnreachable("the lamp does not answer");
* throw AlexaErrors.valueOutOfRange("the lift goes from 0 to 100", { minimumValue: 0, maximumValue: 100 });
* throw AlexaErrors.thermostatIsOff("the thermostat is off"); // sent under Alexa.ThermostatController
*/
export declare const AlexaErrors: {
/** An error of any type, one the table does not have too. */
of(type: string, message: string, extra?: Record<string, unknown>): AlexaError;
/** temperatureValueOutOfRange() under its shorter name. */
temperatureOutOfRange: (message: string, validRange?: ValidRange<Temperature>) => AlexaError;
/** requestedSetpointsTooClose() under its shorter name. */
setpointsTooClose: (message: string, minimumTemperatureDelta?: Temperature) => AlexaError;
/** The value is outside what the endpoint takes. For a temperature: temperatureValueOutOfRange(). */
valueOutOfRange(message: string, validRange?: ValidRange<number>): AlexaError;
temperatureValueOutOfRange(message: string, validRange?: ValidRange<Temperature>): AlexaError;
/** A light showing a color asked for a color temperature: "COLOR". */
notSupportedInCurrentMode(message: string, currentDeviceMode: CurrentDeviceMode): AlexaError;
/** percentageState: what is left of the battery, 0 to 100. */
endpointLowPower(message: string, percentageState?: number): AlexaError;
endpointControlUnavailable(message: string, reason: ControlUnavailableReason): AlexaError;
/** currentChargeLevelInPercentage: the battery level, 0 to 100. */
notSupportedWithCurrentBatteryChargeState(message: string, currentChargeState: ChargeState, currentChargeLevelInPercentage?: number): AlexaError;
/** What has to be refilled. */
insufficientResource(message: string, resourceType: ResourceType): AlexaError;
/** What the user has to do first. */
maintenanceRequired(message: string, maintenanceAction?: MaintenanceAction): AlexaError;
/** Goes under Alexa.ThermostatController. minimumTemperatureDelta: how far apart the setpoints have to be. */
requestedSetpointsTooClose(message: string, minimumTemperatureDelta?: Temperature): AlexaError;
/** Goes under Alexa.SecurityPanelController. With the endpoints listed, the user can bypass them by voice. */
bypassNeeded(message: string, endpointsNeedingBypass?: EndpointNeedingBypass[]): AlexaError;
alreadyInOperation: (message: string) => AlexaError;
bridgeUnreachable: (message: string) => AlexaError;
cloudControlDisabled: (message: string) => AlexaError;
deviceStuck: (message: string) => AlexaError;
doNotDisturbMode: (message: string) => AlexaError;
endpointBusy: (message: string) => AlexaError;
endpointUnreachable: (message: string) => AlexaError;
expiredAuthorizationCredential: (message: string) => AlexaError;
firmwareOutOfDate: (message: string) => AlexaError;
hardwareMalfunction: (message: string) => AlexaError;
insufficientPermissions: (message: string) => AlexaError;
internalError: (message: string) => AlexaError;
invalidAuthorizationCredential: (message: string) => AlexaError;
invalidDirective: (message: string) => AlexaError;
invalidValue: (message: string) => AlexaError;
noSuchEndpoint: (message: string) => AlexaError;
notCalibrated: (message: string) => AlexaError;
notInOperation: (message: string) => AlexaError;
partnerApplicationRedirection: (message: string) => AlexaError;
powerLevelNotSupported: (message: string) => AlexaError;
rateLimitExceeded: (message: string) => AlexaError;
tooManyFailedAttempts: (message: string) => AlexaError;
unableToCharge: (message: string) => AlexaError;
failedToBootstrapCommissioningProcess: (message: string) => AlexaError;
maxCommissioningLimitReached: (message: string) => AlexaError;
childLock: (message: string) => AlexaError;
cookDurationTooLong: (message: string) => AlexaError;
doorClosedTooLong: (message: string) => AlexaError;
doorOpen: (message: string) => AlexaError;
preheatRequired: (message: string) => AlexaError;
probeRequired: (message: string) => AlexaError;
remoteStartNotSupported: (message: string) => AlexaError;
removeProbe: (message: string) => AlexaError;
remoteStartDisabled: (message: string) => AlexaError;
dataDeletionNotSupported: (message: string) => AlexaError;
dataRetrievalNotSupported: (message: string) => AlexaError;
obstacleDetected: (message: string) => AlexaError;
safetyBeamBreached: (message: string) => AlexaError;
authorizationRequired: (message: string) => AlexaError;
notReady: (message: string) => AlexaError;
unauthorized: (message: string) => AlexaError;
unclearedAlarm: (message: string) => AlexaError;
unclearedTrouble: (message: string) => AlexaError;
subscriptionRequired: (message: string) => AlexaError;
disabledByUser: (message: string) => AlexaError;
dualSetpointsUnsupported: (message: string) => AlexaError;
thermostatIsOff: (message: string) => AlexaError;
tripleSetpointsUnsupported: (message: string) => AlexaError;
unsupportedThermostatMode: (message: string) => AlexaError;
unwillingToSetSchedule: (message: string) => AlexaError;
unwillingToSetValue: (message: string) => AlexaError;
configurationUpdateNotAllowed: (message: string) => AlexaError;
coolingLockoutTemperatureValueOutOfRange: (message: string) => AlexaError;
coolingStagesExceedsLimit: (message: string) => AlexaError;
heatingLockoutTemperatureValueOutOfRange: (message: string) => AlexaError;
heatingStagesExceedsLimit: (message: string) => AlexaError;
invalidAuxiliaryHeatingSystemType: (message: string) => AlexaError;
invalidSystemType: (message: string) => AlexaError;
invalidTargetState: (message: string) => AlexaError;
invalidTemperatureScale: (message: string) => AlexaError;
invalidTerminalConnection: (message: string) => AlexaError;
missingSetupInformation: (message: string) => AlexaError;
insufficientSpace: (message: string) => AlexaError;
};
export {};