2019-07-10 00:21:54 +00:00
|
|
|
// Copyright 2019 The Chromium OS Authors. All rights reserved.
|
2018-11-02 07:27:48 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-08-03 03:09:41 +00:00
|
|
|
use base::IoctlNr;
|
2019-07-10 00:21:54 +00:00
|
|
|
use remain::sorted;
|
|
|
|
use std::fmt::{self, Display};
|
|
|
|
use std::io;
|
|
|
|
use std::num;
|
2018-11-02 07:27:48 +00:00
|
|
|
|
2019-07-10 00:21:54 +00:00
|
|
|
#[sorted]
|
|
|
|
#[derive(Debug)]
|
2018-11-02 07:27:48 +00:00
|
|
|
pub enum Error {
|
2019-07-10 00:21:54 +00:00
|
|
|
DescriptorParse,
|
|
|
|
DescriptorRead(io::Error),
|
|
|
|
FdCloneFailed(io::Error),
|
|
|
|
InvalidActualLength(num::TryFromIntError),
|
|
|
|
InvalidBufferLength(num::TryFromIntError),
|
2020-08-03 03:09:41 +00:00
|
|
|
IoctlFailed(IoctlNr, base::Error),
|
2018-11-02 07:27:48 +00:00
|
|
|
NoDevice,
|
2019-07-10 00:21:54 +00:00
|
|
|
NoSuchDescriptor,
|
|
|
|
RcGetMutFailed,
|
|
|
|
RcUnwrapFailed,
|
|
|
|
TransferAlreadyCompleted,
|
2018-11-02 07:27:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 00:21:54 +00:00
|
|
|
impl Display for Error {
|
|
|
|
#[remain::check]
|
2018-11-02 07:27:48 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2019-07-10 00:21:54 +00:00
|
|
|
use self::Error::*;
|
2018-11-02 07:27:48 +00:00
|
|
|
|
2019-07-10 00:21:54 +00:00
|
|
|
#[sorted]
|
|
|
|
match self {
|
|
|
|
DescriptorParse => write!(f, "parsing descriptors failed"),
|
|
|
|
DescriptorRead(e) => write!(f, "reading descriptors from device failed: {}", e),
|
|
|
|
FdCloneFailed(e) => write!(f, "File::try_clone() failed: {}", e),
|
|
|
|
InvalidActualLength(e) => write!(f, "invalid actual_length in URB: {}", e),
|
|
|
|
InvalidBufferLength(e) => write!(f, "invalid transfer buffer length: {}", e),
|
|
|
|
IoctlFailed(nr, e) => write!(f, "USB ioctl 0x{:x} failed: {}", nr, e),
|
|
|
|
NoDevice => write!(f, "Device has been removed"),
|
|
|
|
NoSuchDescriptor => write!(f, "Requested descriptor not found"),
|
|
|
|
RcGetMutFailed => write!(f, "Rc::get_mut failed"),
|
|
|
|
RcUnwrapFailed => write!(f, "Rc::try_unwrap failed"),
|
|
|
|
TransferAlreadyCompleted => write!(f, "attempted to cancel already-completed transfer"),
|
2018-11-02 07:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
2019-07-10 00:21:54 +00:00
|
|
|
impl std::error::Error for Error {}
|