bt_bass/client/
error.rs

1// Copyright 2023 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 thiserror::Error;
6
7use bt_bap::types::BroadcastId;
8use bt_common::packet_encoding::Error as PacketError;
9use bt_gatt::types::{Error as BTGattError, Handle};
10
11#[derive(Debug, Error)]
12pub enum Error {
13    #[error(
14        "An unsupported opcode ({0:#x}) used in a Broadcast Audio Scan Control Point operation"
15    )]
16    OpCodeNotSupported(u8),
17
18    #[error("Invalid source id ({0:#x}) used in a Broadcast Audio Scan Control Point operation")]
19    InvalidSourceId(u8),
20
21    #[error("Packet serialization/deserialization error: {0}")]
22    Packet(PacketError),
23
24    #[error("Malformed service on peer: {0}")]
25    Service(ServiceError),
26
27    #[error("GATT operation error: {0}")]
28    Gatt(BTGattError),
29
30    #[error("Error while polling BASS client event stream: {0}")]
31    EventStream(Box<Error>),
32
33    #[error("Broadcast source with id ({0:?}) is unknown")]
34    UnknownBroadcastSource(BroadcastId),
35
36    #[error("Failure occurred: {0}")]
37    Generic(String),
38}
39
40/// This error represents an error we found at the remote BASS service or
41/// we encountered during the interaction with the remote service which
42/// prevents us from proceeding further with the client operation.
43#[derive(Debug, Error, PartialEq)]
44pub enum ServiceError {
45    #[error("Missing a required service characteristic")]
46    MissingCharacteristic,
47
48    #[error("More than one Broadcast Audio Scan Control Point characteristics")]
49    ExtraScanControlPointCharacteristic,
50
51    #[error(
52        "Failed to configure notification for Broadcast Recieve State characteristic (handle={0:?})"
53    )]
54    NotificationConfig(Handle),
55
56    #[error("Broadcast Receive State notification channels closed unexpectedly: {0}")]
57    NotificationChannelClosed(String),
58}