Skip to main content

bt_rfcomm/frame/
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 thiserror::Error;
6
7use crate::Role;
8use crate::frame::FrameTypeMarker;
9
10/// Errors associated with parsing an RFCOMM Frame.
11#[derive(Error, Debug)]
12pub enum FrameParseError {
13    #[error("Provided buffer is too small")]
14    BufferTooSmall,
15    #[error("Invalid buffer size provided. Expected: {}, Actual: {}", .0, .1)]
16    InvalidBufferLength(usize, usize),
17    #[error("Frame length {0} exceeds maximum allowed size (32767)")]
18    FrameTooLarge(usize),
19    #[error("FCS check for the Frame failed")]
20    FCSCheckFailed,
21    #[error("Invalid Role when parsing frame: {:?}", .0)]
22    InvalidRole(Role),
23    #[error("DLCI ({:?}) is invalid", .0)]
24    InvalidDLCI(u8),
25    #[error("Frame is invalid")]
26    InvalidFrame,
27    #[error("Frame type not supported before mux startup: {:?})", .0)]
28    InvalidFrameBeforeMuxStartup(FrameTypeMarker),
29    #[error("Frame type is unsupported")]
30    UnsupportedFrameType,
31    #[error("Mux Command type {} is unsupported", .0)]
32    UnsupportedMuxCommandType(u8),
33    #[error("Value is out of range")]
34    OutOfRange,
35    #[error(transparent)]
36    Other(#[from] anyhow::Error),
37}