blob: 3a3ddf2c0d075e7deed9b29fa1dc0c8a756df95e [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use {fidl_fuchsia_bluetooth as bt, thiserror::Error};
/// Error type that can be constructed from a Bluetooth FIDL Error or from on its own.
#[derive(Debug, Error)]
#[error("{}", message)]
pub struct Error {
message: String,
}
impl Error {
/// Constructs an Error with a message.
pub fn new(msg: &str) -> Error {
Error { message: msg.to_string() }
}
}
impl From<bt::Error> for Error {
fn from(err: bt::Error) -> Error {
Error {
message: match err.description {
Some(d) => d,
None => "unknown Bluetooth FIDL error".to_string(),
},
}
}
}
impl From<bt::ErrorCode> for Error {
fn from(err: bt::ErrorCode) -> Error {
Error { message: format!("Bluetooth Error Code {:?}", err) }
}
}
impl From<fidl::Error> for Error {
fn from(err: fidl::Error) -> Error {
Error { message: format!("FIDL error: {}", err) }
}
}