--- title: "Errors and recovery" description: "Handle the three errors every Camera operation throws, decide when a retry is safe, read the PTP error behind one, and recover a camera that stopped answering." url: https://darkgrade.com/docs/slate/guides/errors last_updated: 2026-12-04 docs_index: https://darkgrade.com/docs/llms.txt --- # Errors and recovery > Handle the three errors every Camera operation throws, decide when a retry is safe, read the PTP error behind one, and recover a camera that stopped answering. > ## Documentation Index > Fetch the complete documentation index at: https://darkgrade.com/docs/llms.txt > Use this file to discover all available pages before exploring further. Every `Camera` operation in Darkgrade Slate fails in one of three ways. The class tells you whether anything reached the camera, and so whether a retry is safe. ```typescript import { Camera, CameraOutcomeUnknownError, CameraRefusedError, CameraUnsupportedError, } from '@darkgrade/slate' const camera = new Camera() await camera.connect() try { await camera.setIso('ISO 800') } catch (error) { if (error instanceof CameraUnsupportedError) { // Nothing was sent. getCapabilities() says why. } else if (error instanceof CameraRefusedError) { // The camera said no, or doesn't offer that value now. // Nothing changed. } else if (error instanceof CameraOutcomeUnknownError) { // Sent, not confirmed. Read the camera before you send it again. console.log(await camera.getIso()) } else { throw error } } finally { await camera.disconnect() } ``` ## The three errors - [`CameraUnsupportedError`](https://darkgrade.com/docs/slate/reference/errors.md#cameraunsupportederror): this camera can't do it right now. Nothing was sent. **Retry?** Not as it stands. Read [`getCapabilities()`](https://darkgrade.com/docs/functionality/connection.md#what-the-camera-can-do): `operations` gives the reason for a method, `controls` shows whether a setting is there and writable. Change the mode or lens, then call again. - [`CameraRefusedError`](https://darkgrade.com/docs/slate/reference/errors.md#camerarefusederror): the camera said no, or the value isn't one it offers now. Nothing changed. **Retry?** Yes, with a value from the setting's [`allowedValues`](https://darkgrade.com/docs/slate/reference/types-capabilities.md#cameracontrolstate), or once the camera is no longer busy. - [`CameraOutcomeUnknownError`](https://darkgrade.com/docs/slate/reference/errors.md#cameraoutcomeunknownerror): the command was sent but its result could not be confirmed. Slate never resends it. **Retry?** Only after you read the camera's state. A second shutter or a second Stop is yours to decide. Each error has `operation`: the method name (`'takePhoto'`) or the setting id (`'iso'`) that failed, so you can report it without parsing `message`. When a transport or protocol failure is behind it, that error is [`cause`](#read-the-cause). Two errors are kinds of `CameraOutcomeUnknownError`, so one `instanceof` check catches them: - [`CameraConfirmationError`](https://darkgrade.com/docs/slate/reference/errors.md#cameraconfirmationerror): the camera acknowledged a write, but a fresh read did not show the requested state. It has `expected` and `observed`. - [`CameraClipNotFoundError`](https://darkgrade.com/docs/slate/reference/errors.md#cameraclipnotfounderror): the camera stopped recording, but no new clip appeared on the card in time. The footage stays on the card: [`listMedia()`](https://darkgrade.com/docs/functionality/media.md#list-photos-and-clips) finds it later. ### Other errors A few failures keep their own class, which is why the example above ends with `throw error`: - **An argument of the wrong shape.** `connect()` and `on()` throw `TypeError`, for example for `connect({ usb: … })` in place of `connect({ device })`. Nothing is sent. - **No camera to open.** `connect()` throws a plain `Error` when no USB device matches, or when several do: `Multiple USB cameras match; select a unique serialNumber before connecting`. See [Choose a camera](https://darkgrade.com/docs/slate/guides/multiple-cameras.md). - **A protocol error that was not wrapped.** Some reads rethrow a `PTPError` as it is, such as a timeout during `getBattery()`. Handle it like the same class as a [`cause`](#read-the-cause). ## A camera that stopped answering A timeout or a broken reply leaves a half-finished exchange on the cable. On USB, Slate resets the connection by itself before the next command: see [After a timeout](https://darkgrade.com/docs/slate/guides/timeouts-and-logging.md#after-a-timeout). When that isn't enough, call [`recover()`](https://darkgrade.com/docs/slate/getting_started/camera.md#recover): ```typescript const report = await camera.recover() if (report.recovered) { await camera.connect() // recover() leaves the camera closed } else if (report.needsPhysicalAction) { console.error('Power-cycle the camera or replug the cable') } console.log(report.steps) // [{ step: 'session', ok: true, durationMilliseconds: 412 }] ``` `recover()` tries a fresh session, then a PTP Device Reset, then a USB port reset, and stops at the first step after which the camera answers. The options and the full report are in [Recover a stuck camera](https://darkgrade.com/docs/functionality/connection.md#recover-a-stuck-camera). > [!NOTE] > > `needsPhysicalAction: true` is the only signal that power or hub cycling is warranted. A busy camera, a refusal or a single timeout is not. ## Read the cause `cause` holds the protocol error behind a public error. All of them extend `PTPError`; the [Errors reference](https://darkgrade.com/docs/slate/reference/errors.md#protocol-errors) lists their fields. - [`PTPTimeoutError`](https://darkgrade.com/docs/slate/reference/errors.md#ptptimeouterror): the camera did not answer in time and may still be working. Read its state before you repeat anything. - [`PTPResponseError`](https://darkgrade.com/docs/slate/reference/errors.md#ptpresponseerror): the camera answered with a [response code](https://darkgrade.com/docs/slate/ptp-reference/response-definitions.md), in `code`. Nothing is wrong with the connection. - [`PTPProtocolError`](https://darkgrade.com/docs/slate/reference/errors.md#ptpprotocolerror) and [`PTPDecodeError`](https://darkgrade.com/docs/slate/reference/errors.md#ptpdecodeerror): the reply broke PTP's framing or could not be decoded. Read the camera's state before you repeat anything. - [`PTPDisconnectedError`](https://darkgrade.com/docs/slate/reference/errors.md#ptpdisconnectederror): the cable was pulled, the camera turned off or the socket closed. Call `connect()` again. - [`PTPRecoveryRequiredError`](https://darkgrade.com/docs/slate/reference/errors.md#ptprecoveryrequirederror): an earlier failure left the connection unusable. Call `disconnect()` and `connect()`, or `recover()`. ```typescript import { CameraOutcomeUnknownError, PTPDisconnectedError, PTPTimeoutError, } from '@darkgrade/slate' try { await camera.getInfo() } catch (error) { if (error instanceof CameraOutcomeUnknownError) { const { cause } = error if (cause instanceof PTPDisconnectedError) { console.error('The camera went away') } if (cause instanceof PTPTimeoutError) { console.error(`No ${cause.phase} in time`) } } } ``` ### DeviceBusy (0x2019) - **Cause.** The camera can't start this operation right now, usually because it is still finishing something else, such as writing a photo to the card or changing mode. PTP defines [DeviceBusy](https://darkgrade.com/docs/slate/ptp-reference/response-definitions.md#devicebusy-0x2019) as "not performed", so nothing changed. - **What Slate does.** It sends a standard PTP operation again by itself: up to 6 retries, waiting 50 ms and doubling each time, for at most 2 seconds. You see the code only when the camera is still busy after that. [`transactionPolicy`](https://darkgrade.com/docs/slate/guides/timeouts-and-logging.md) changes those limits. - **Fix.** Wait and call again: a retry is safe. If it keeps coming back, let the camera finish what it is doing first. ### SessionAlreadyOpen (0x201E) - **Cause.** The camera still holds a [session](https://darkgrade.com/docs/slate/getting_started/what-is-ptp.md#sessions) from an earlier connection, usually a program that exited without closing it. A camera serves one session at a time and answers OpenSession with [SessionAlreadyOpen](https://darkgrade.com/docs/slate/ptp-reference/response-definitions.md#sessionalreadyopen-0x201e). - **What Slate does.** `connect()` handles it: it closes the stale session and opens a new one, so you don't normally see this code from `Camera`. - **Fix.** With [raw protocol access](https://darkgrade.com/docs/slate/guides/protocol.md) or another PTP library, send CloseSession and open the session again. If another program is really using the camera, close that program first: only one can hold the connection. ### Sony AuthenticationFailed (0xA101) - **Cause.** A Sony camera refused the handshake that starts remote control. Sony defines [AuthenticationFailed](https://darkgrade.com/docs/slate/ptp-reference/vendors/sony/sony-response-definitions.md#authenticationfailed-0xa101) as: the computer announced an older protocol version than the camera's, or authentication failed for another reason. The code is in Sony's vendor range, so it has this meaning only on a Sony. - **What Slate does.** During `connect()` it announces protocol version 3.00, then 2.00 for older bodies. If the camera refuses both, `connect()` throws `CameraRefusedError` whose `cause` is a `PTPResponseError` with `code` `0xA101`. - **Fix.** Check the camera's USB connection mode is **PC Remote** (or **Remote Shooting**), not Mass Storage, close other apps that use the camera, replug it and connect again. If it still refuses, [tell us](https://darkgrade.com/docs/overview/help.md#what-to-include) the model and firmware version. The messages these and other failures print in Studio, MCP, the CLI and Slate are listed in [Error messages](https://darkgrade.com/docs/overview/errors.md), and every standard code is in [Responses](https://darkgrade.com/docs/slate/ptp-reference/response-definitions.md). `connect`, `getInfo`, `recover` and `disconnect` always wrap: a `PTPResponseError` becomes `CameraRefusedError`, and any other `PTPError` becomes `CameraOutcomeUnknownError`. With [raw protocol access](https://darkgrade.com/docs/slate/guides/protocol.md) you catch these classes directly. ## A camera another process is using `HardwareBusyError`, from `@darkgrade/slate/runtime`, means a host that shares cameras between processes would not let the call run now. Wait `retryAfterMilliseconds` and try again: see [A busy camera](https://darkgrade.com/docs/slate/guides/runtime.md#a-busy-camera). ## Still stuck? [Get help](https://darkgrade.com/docs/overview/help.md#what-to-include) says where to ask and what to send. > [card] [Errors reference](https://darkgrade.com/docs/slate/reference/errors.md) > > Every error class, what it extends and its fields. > [card] [Timeouts and logging](https://darkgrade.com/docs/slate/guides/timeouts-and-logging.md) > > How long Slate waits, and how often it retries a busy camera.