profile_client/
error.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fidl_fuchsia_bluetooth_bredr as bredr;
6use thiserror::Error;
7
8#[derive(Error, Debug)]
9pub enum Error {
10    /// An attempt to add a search to an already terminated `ProfileClient`.
11    #[error("Error adding search to already terminated ProfileClient")]
12    AlreadyTerminated,
13    /// A search result stream produced an error.
14    #[error("Search Result stream ended in error: {:?}", source)]
15    SearchResult { source: Box<dyn std::error::Error + Send + Sync> },
16    /// A connection receiver finished with an error.
17    #[error("Connection Receiver stream ended in error: {:?}", source)]
18    ConnectionReceiver { source: Box<dyn std::error::Error + Send + Sync> },
19    /// The services advertised were completed unexpectedly. `result` contains the response from
20    /// the profile advertise call.
21    #[error("Advertisement ended prematurely: {:?}", result)]
22    Advertisement { result: bredr::ProfileAdvertiseResult },
23    /// Another FIDL error has occurred.
24    #[error("FIDL Error occurred: {:?}", source)]
25    Fidl { source: fidl::Error },
26}
27
28impl Error {
29    pub fn connection_receiver<E>(e: E) -> Self
30    where
31        E: Into<Box<dyn std::error::Error + Send + Sync>>,
32    {
33        Self::ConnectionReceiver { source: e.into() }
34    }
35
36    pub fn search_result<E>(e: E) -> Self
37    where
38        E: Into<Box<dyn std::error::Error + Send + Sync>>,
39    {
40        Self::SearchResult { source: e.into() }
41    }
42}
43
44impl From<fidl::Error> for Error {
45    fn from(source: fidl::Error) -> Self {
46        Self::Fidl { source }
47    }
48}