pub enum PtpError {
Usb(Error),
Protocol {
code: ResponseCode,
operation: OperationCode,
},
InvalidData {
message: String,
},
Io(Error),
Timeout,
Disconnected,
SessionNotOpen,
NoDevice,
Cancelled,
DeviceReset,
}Expand description
The main error type for mtp-rs operations.
Variants§
Usb(Error)
USB communication error
Protocol
Protocol-level error from device
Fields
code: ResponseCodeThe response code returned by the device.
operation: OperationCodeThe operation that triggered the error.
InvalidData
Invalid data received from device
Io(Error)
I/O error
Timeout
Operation timed out
Disconnected
Device was disconnected
SessionNotOpen
Session not open
NoDevice
No device found
Cancelled
Operation cancelled
DeviceReset
A transfer cancel wedged the device, and the transport was reset to recover it. The PTP session is gone; reopen the device to continue.
Seen when cancelling or abandoning an in-flight read on an Android device
(issue #18): the device stops responding, so cancel_transfer issues a
USB DEVICE_RESET and reports this instead of a false success. Transfer
size doesn’t drive it; a 36-byte file is enough.
Don’t treat this as the only wedge signature. A Samsung reports it; a
Pixel wedges the same way but the next operation simply hangs with no
error at all (verified on a Pixel 9 Pro XL, macOS/nusb, 2026-07-20), so
wrap operations in a timeout as well as matching this variant. See
docs/notes/android-wedges-and-the-reset-kill-switch.md.
Implementations§
Source§impl PtpError
impl PtpError
Sourcepub fn invalid_data(message: impl Into<String>) -> Self
pub fn invalid_data(message: impl Into<String>) -> Self
Create an invalid data error with a message.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Check if this is a retryable error.
Retryable errors are transient and the operation may succeed if retried:
DeviceBusy: Device is temporarily busyTimeout: Operation timed out but device may still be responsive
Sourcepub fn response_code(&self) -> Option<ResponseCode>
pub fn response_code(&self) -> Option<ResponseCode>
Get the response code if this is a protocol error.
Sourcepub fn is_exclusive_access(&self) -> bool
pub fn is_exclusive_access(&self) -> bool
Check if this error indicates another process has exclusive access to the device.
This typically happens on macOS when ptpcamerad or another application
has already claimed the USB interface. Applications can use this to provide
platform-specific guidance to users.
§Example
match device.open().await {
Err(e) if e.is_exclusive_access() => {
// On macOS, likely ptpcamerad interference
// App can query IORegistry for UsbExclusiveOwner to get details
show_exclusive_access_help();
}
Err(e) => handle_other_error(e),
Ok(dev) => use_device(dev),
}Trait Implementations§
Source§impl Error for PtpError
impl Error for PtpError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()