Skip to main content
API referenceErrors reference

A Camera operation fails in one of three ways, and the class tells you what happened to the camera: nothing was sent, the camera said no, or the command went out and was not confirmed. Branch on the class, never on the message.

import {
    CameraOutcomeUnknownError,
    CameraRefusedError,
    CameraUnsupportedError,
} from '@darkgrade/slate'

try {
    await camera.setIso('ISO 800')
} catch (error) {
    if (error instanceof CameraUnsupportedError) {
        // Nothing was sent: no ISO setting in this mode.
    } else if (error instanceof CameraRefusedError) {
        // Nothing changed: offer the values listed now.
        const { controls } = await camera.getCapabilities()
        console.log(controls.iso?.allowedValues)
    } else if (error instanceof CameraOutcomeUnknownError) {
        // Sent, not confirmed, never resent: read first.
        console.log(await camera.getIso(), error.cause)
    } else throw error
}

Guide: Errors and recovery

Camera errors

ErrorMeaning
CameraUnsupportedErrorThis camera cannot do it right now; getCapabilities() says why. Nothing was sent.
CameraRefusedErrorThe camera said no, or the value is not one it offers now. Nothing changed.
CameraOutcomeUnknownErrorThe command was sent but its result could not be confirmed. It is never resent, so a photo, a stop or a setting write is never repeated by accident; read the camera again before retrying.
CameraConfirmationErrorAn acknowledged request whose fresh camera observation did not confirm the requested state.
CameraClipNotFoundErrorThe camera confirmed it stopped recording, but no new finished clip appeared on the card in time. Stop is not resent; any footage stays on the card, where listing the card finds it later.

Each carries operation, so a host can say which request failed without reading the message. An argument of the wrong shape is not a camera outcome: connect() and on() throw a plain TypeError for one, before anything is sent. A failed device selection before any command (no matching USB device, or several) is rethrown as it is.

How connection failures become these errors

connect, getInfo, recover and disconnect report a failure as one of the three public error types, keeping the driver's error as cause: a PTP response the camera refused becomes CameraRefusedError; a timeout, lost transport, unreadable reply, pending recovery or failed cleanup becomes CameraOutcomeUnknownError, since the session's state was not confirmed. Device selection failures before any command (no matching USB device, several matches) and invalid arguments are not camera outcomes and are rethrown unchanged.

Protocol errors

The failures of the connection under a Camera: a cable, a transport or a camera that misbehaves. They reach you directly from raw calls on protocolSession(camera), and as the cause of a Camera error. Every one carries the operation and transaction it happened in.

ErrorMeaning
PTPErrorThe base class of every protocol failure. Catch it to handle all of them at once.
PTPDecodeErrorA dataset arrived intact at the container level but could not be decoded.
PTPDisconnectedErrorThe transport is gone (cable pulled, camera powered off, socket closed). Reconnect to continue.
PTPProtocolErrorThe camera answered with bytes that break ISO 15740 container framing for this transaction.
PTPRecoveryRequiredErrorThe pipe may still contain an abandoned transaction and the automatic USB reset failed, or the transport has none (PTP/IP). Commands stay blocked until a disconnect/connect or caller-owned recovery.
PTPResponseErrorThe camera answered a transaction with a response code the caller cannot continue from.
PTPTimeoutErrorA transport phase did not complete in time. The camera may still be busy with the transaction.

CameraUnsupportedError

extends Error

This camera cannot do it right now; getCapabilities() says why. Nothing was sent.

When The connected camera has no such operation, cannot do it in its current mode, or cannot do an option you asked for. A typed getter also throws it when the setting is absent on this camera, does not apply now, or holds a value Slate has no name for.

What to do For a method, getCapabilities().operations[error.operation] has the reason, in words you can show a person; for a setting, getCapabilities().controls[error.operation] shows whether it is present, enabled and writable. Nothing was sent, so calling again once the mode, lens or card changes is safe.

operationstring

The method name or setting id that failed.

messagestring

What happened, in words you can show a person.

cause?unknown

The transport or protocol error behind it, when one caused it.

CameraRefusedError

extends Error

The camera said no, or the value is not one it offers now. Nothing changed.

When The camera answered no, the value is not one of the setting's allowedValues now, or an argument was malformed (a takePhoto option, a preview size, an invalid Date). takePhoto is also refused while the camera records.

What to do Nothing changed. Read getCapabilities() for the values offered now and choose one of them, or fix the argument, then call again.

operationstring

The method name or setting id that failed.

messagestring

What happened, in words you can show a person.

cause?unknown

The transport or protocol error behind it, when one caused it.

CameraOutcomeUnknownError

extends Error

The command was sent but its result could not be confirmed. It is never resent, so a photo, a stop or a setting write is never repeated by accident; read the camera again before retrying.

When The command went out and its result could not be confirmed: a timeout, a lost connection, an unreadable reply, a photo whose file never appeared, a lens that did not reach the focal length asked for.

What to do Slate never resends, and neither should you without looking. Read the camera first (getCapabilities(), listMedia(), getRecordingState()), then decide. error.cause holds the transport or protocol error when one is behind it.

operationstring

The method name or setting id that failed.

messagestring

What happened, in words you can show a person.

cause?unknown

The transport or protocol error behind it, when one caused it.

CameraConfirmationError

extends CameraOutcomeUnknownError › Error

When The camera acknowledged a setting write, or a recording start or stop, but a fresh read did not show the requested state in time. operation is the setting's id, or record_start or record_stop.

What to do Compare expected with observed, read getCapabilities() again, and only then write again.

operationstring

The method name or setting id that failed.

expectedstring

The value or state that was asked for.

observedstring | null

What the camera showed instead; null when it showed nothing.

messagestring

What happened, in words you can show a person.

cause?unknown

The transport or protocol error behind it, when one caused it.

CameraClipNotFoundError

extends CameraOutcomeUnknownError › Error

When stopRecording() saw the camera stop, but no new finished clip appeared on the card in time.

What to do Stop is not resent and the footage stays on the card: listMedia() finds it later.

operationstring

The method name or setting id that failed. Inherited from CameraOutcomeUnknownError.

messagestring

What happened, in words you can show a person.

cause?unknown

The transport or protocol error behind it, when one caused it.

PTPError

extends Error

When The base class of every protocol failure. Catch it to handle all of them at once.

What to do Branch on the subclass. operation and transactionId say which transaction failed.

operation?string

The PTP operation of the transaction that failed, when known.

transactionId?number

The transaction it happened in, when known.

messagestring

What happened, in words you can show a person.

cause?unknown

The lower-level error behind it, when there is one.

PTPDecodeError

extends PTPError › Error

When A dataset arrived whole but could not be decoded.

What to do The session is still usable. The camera sent a shape Slate does not know; report the model and firmware.

operation?string

The PTP operation of the transaction that failed, when known. Inherited from PTPError.

transactionId?number

The transaction it happened in, when known. Inherited from PTPError.

messagestring

What happened, in words you can show a person.

cause?unknown

The lower-level error behind it, when there is one.

PTPDisconnectedError

extends PTPError › Error

When The transport is gone: the cable was pulled, the camera powered off, or the socket closed.

What to do Call connect() again once the camera is back.

operation?string

The PTP operation of the transaction that failed, when known. Inherited from PTPError.

transactionId?number

The transaction it happened in, when known. Inherited from PTPError.

messagestring

What happened, in words you can show a person.

cause?unknown

The lower-level error behind it, when there is one.

PTPProtocolError

extends PTPError › Error

When The camera answered with bytes that break PTP container framing. violation names how.

What to do Treat the session as out of step: disconnect and connect again, or call recover().

violationPTPProtocolViolation

How the reply broke the framing.

See PTPProtocolViolation.

operation?string

The PTP operation of the transaction that failed, when known. Inherited from PTPError.

transactionId?number

The transaction it happened in, when known. Inherited from PTPError.

messagestring

What happened, in words you can show a person.

cause?unknown

The lower-level error behind it, when there is one.

PTPRecoveryRequiredError

extends PTPError › Error

When An abandoned transaction may still be in the pipe and the automatic USB reset failed, or the transport has none (PTP/IP). Every command fails with it until the session is replaced.

What to do Call disconnect() then connect(), or recover().

operation?string

The PTP operation of the transaction that failed, when known. Inherited from PTPError.

transactionId?number

The transaction it happened in, when known. Inherited from PTPError.

messagestring

What happened, in words you can show a person.

cause?unknown

The lower-level error behind it, when there is one.

PTPResponseError

extends PTPError › Error

When The camera answered with a response code the caller cannot continue from. code is the PTP response code.

What to do Look the code up in the response definitions. On the connection operations it becomes CameraRefusedError.

codenumber

The PTP response code the camera answered with.

operation?string

The PTP operation of the transaction that failed, when known. Inherited from PTPError.

transactionId?number

The transaction it happened in, when known. Inherited from PTPError.

messagestring

What happened, in words you can show a person.

cause?unknown

The lower-level error behind it, when there is one.

PTPTimeoutError

extends PTPError › Error

When A send, data or response phase did not complete within the transaction policy. phase says which.

What to do The camera may still be working on the transaction. On USB, Slate resets the pipe before the next command unless automaticUSBReset is off; raise timeoutMilliseconds in transactionPolicy for slow operations.

phase'send' | 'data' | 'response'

The phase of the transaction that timed out.

timeoutMillisecondsnumber

How long Slate waited.

operation?string

The PTP operation of the transaction that failed, when known. Inherited from PTPError.

transactionId?number

The transaction it happened in, when known. Inherited from PTPError.

messagestring

What happened, in words you can show a person.

cause?unknown

The lower-level error behind it, when there is one.

Errors of other entry points

Thrown by code outside Camera, and exported from the entry point named.

ErrorImport from, and meaning
PTPIPTransactionCancelledError@darkgrade/slate/protocol A wire Cancel is a cancelled transaction, never an invented PTP response code.
HardwareBusyError@darkgrade/slate/runtime Another operation or process holds the camera. Carries status (409), code (HARDWARE_BUSY) and retryAfterMilliseconds.
OperationInputError@darkgrade/slate/runtime A call's inputs do not match the operation's parameters; nothing was sent to a camera.
TelemetryError@darkgrade/slate/telemetry/server The collector refuses a request: status is the HTTP status to answer with, retryAfterSeconds when to try again.
InvalidMatrixCursor@darkgrade/slate/telemetry/server A page of the Matrix export was asked for with a cursor the collector cannot read.
MatrixExportChanged@darkgrade/slate/telemetry/server The Matrix export changed or expired between pages: restart the synchronisation from its first page.
⌘I