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
| Error | Meaning |
|---|---|
CameraUnsupportedError | This camera cannot do it right now; getCapabilities() says why. Nothing was sent. |
CameraRefusedError | The camera said no, or the value is not one it offers now. Nothing changed. |
CameraOutcomeUnknownError | 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. |
CameraConfirmationError | An acknowledged request whose fresh camera observation did not confirm the requested state. |
CameraClipNotFoundError | The 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
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.
| Error | Meaning |
|---|---|
PTPError | The base class of every protocol failure. Catch it to handle all of them at once. |
PTPDecodeError | A dataset arrived intact at the container level but could not be decoded. |
PTPDisconnectedError | The transport is gone (cable pulled, camera powered off, socket closed). Reconnect to continue. |
PTPProtocolError | The camera answered with bytes that break ISO 15740 container framing for this transaction. |
PTPRecoveryRequiredError | The 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. |
PTPResponseError | The camera answered a transaction with a response code the caller cannot continue from. |
PTPTimeoutError | A transport phase did not complete in time. The camera may still be busy with the transaction. |
CameraUnsupportedError
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.
The method name or setting id that failed.
What happened, in words you can show a person.
The transport or protocol error behind it, when one caused it.
CameraRefusedError
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.
The method name or setting id that failed.
What happened, in words you can show a person.
The transport or protocol error behind it, when one caused it.
CameraOutcomeUnknownError
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.
The method name or setting id that failed.
What happened, in words you can show a person.
The transport or protocol error behind it, when one caused it.
CameraConfirmationError
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.
The method name or setting id that failed.
The value or state that was asked for.
What the camera showed instead; null when it showed nothing.
What happened, in words you can show a person.
The transport or protocol error behind it, when one caused it.
CameraClipNotFoundError
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.
The method name or setting id that failed. Inherited from CameraOutcomeUnknownError.
What happened, in words you can show a person.
The transport or protocol error behind it, when one caused it.
PTPError
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.
The PTP operation of the transaction that failed, when known.
The transaction it happened in, when known.
What happened, in words you can show a person.
The lower-level error behind it, when there is one.
PTPDecodeError
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.
The PTP operation of the transaction that failed, when known. Inherited from PTPError.
The transaction it happened in, when known. Inherited from PTPError.
What happened, in words you can show a person.
The lower-level error behind it, when there is one.
PTPDisconnectedError
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.
The PTP operation of the transaction that failed, when known. Inherited from PTPError.
The transaction it happened in, when known. Inherited from PTPError.
What happened, in words you can show a person.
The lower-level error behind it, when there is one.
PTPProtocolError
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().
How the reply broke the framing.
See PTPProtocolViolation.
The PTP operation of the transaction that failed, when known. Inherited from PTPError.
The transaction it happened in, when known. Inherited from PTPError.
What happened, in words you can show a person.
The lower-level error behind it, when there is one.
PTPRecoveryRequiredError
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().
The PTP operation of the transaction that failed, when known. Inherited from PTPError.
The transaction it happened in, when known. Inherited from PTPError.
What happened, in words you can show a person.
The lower-level error behind it, when there is one.
PTPResponseError
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.
The PTP response code the camera answered with.
The PTP operation of the transaction that failed, when known. Inherited from PTPError.
The transaction it happened in, when known. Inherited from PTPError.
What happened, in words you can show a person.
The lower-level error behind it, when there is one.
PTPTimeoutError
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.
The phase of the transaction that timed out.
How long Slate waited.
The PTP operation of the transaction that failed, when known. Inherited from PTPError.
The transaction it happened in, when known. Inherited from PTPError.
What happened, in words you can show a person.
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.
| Error | Import 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. |