usb_util/
error.rs

1// Copyright 2019 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use std::io;
6use std::num;
7
8use base::IoctlNr;
9use remain::sorted;
10use thiserror::Error;
11
12#[sorted]
13#[derive(Error, Debug)]
14pub enum Error {
15    #[error("parsing descriptors failed")]
16    DescriptorParse,
17    #[error("reading descriptors from device failed: {0}")]
18    DescriptorRead(io::Error),
19    #[error("File::try_clone() failed: {0}")]
20    FdCloneFailed(io::Error),
21    #[error("getting a dma buffer of size {0:x} failed")]
22    GetDmaBufferFailed(usize),
23    #[error("invalid actual_length in URB: {0}")]
24    InvalidActualLength(num::TryFromIntError),
25    #[error("invalid transfer buffer")]
26    InvalidBuffer,
27    #[error("invalid transfer buffer length: {0}")]
28    InvalidBufferLength(num::TryFromIntError),
29    #[error("invalid ISOC packet count")]
30    InvalidISOCPacketCount,
31    #[error("USB ioctl 0x{0:x} failed: {1}")]
32    IoctlFailed(IoctlNr, base::Error),
33    #[error("USB mmap failed: {0}")]
34    MmapFailed(base::MmapError),
35    #[error("Device has been removed")]
36    NoDevice,
37    #[error("Requested descriptor not found")]
38    NoSuchDescriptor,
39    #[error("Rc::get_mut failed")]
40    RcGetMutFailed,
41    #[error("Rc::try_unwrap failed")]
42    RcUnwrapFailed,
43    #[error("releasing the dma buffer failed")]
44    ReleaseDmaBufferFailed,
45    #[error("attempted to cancel already-completed transfer")]
46    TransferAlreadyCompleted,
47}
48
49pub type Result<T> = std::result::Result<T, Error>;