fdomain_uart_driver_lib/error.rs
1// Copyright 2026 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
5//! Error types for the target-side FDomain UART driver.
6
7use thiserror::Error;
8
9/// Errors produced during target-side UART driver operation.
10#[derive(Error, Debug)]
11pub enum TargetDriverError {
12 /// FIDL channel or proxy communication failure.
13 #[error("FIDL communication error: {0}")]
14 Fidl(#[from] fidl::Error),
15 /// Non-OK status code returned by the serial hardware driver.
16 #[error("Serial driver error status: {0}")]
17 DriverStatus(i32),
18 /// Empty byte vector returned during handshake read.
19 #[error("Serial read returned empty data")]
20 EmptyRead,
21 /// End-of-file reached when reading frames from the serial device.
22 #[error("EOF from serial driver")]
23 Eof,
24 /// Protocol negotiation frame decoding or validation failure.
25 #[error("Handshake error: {0}")]
26 Handshake(#[from] uart_fpl::HandshakeError),
27 /// Host and target share no supported framing protocol version.
28 #[error("No common protocol negotiated")]
29 NoCommonProtocol,
30 /// Filesystem or I/O failure while discovering serial devices.
31 #[error("I/O error: {0}")]
32 Io(#[from] std::io::Error),
33 /// Serial device directory entry path is not valid UTF-8.
34 #[error("Non-UTF-8 serial device path")]
35 NonUtf8Path,
36 /// No usable serial ports found under `/dev/class/serial`.
37 #[error("No serial ports found")]
38 NoSerialPorts,
39 /// Serial write failed after exhausting all retry attempts.
40 #[error("Failed to write to serial after exhausting retry attempts")]
41 WriteRetriesExhausted,
42 /// Host sent a control reset or control channel close frame.
43 #[error("Host requested protocol reset")]
44 ResetRequested,
45 /// Host initiated a new handshake with a different session ID.
46 #[error("Session ID changed")]
47 SessionIdChanged,
48 /// Internal ACK notification channel closed unexpectedly.
49 #[error("ACK channel closed")]
50 AckChannelClosed,
51 /// Frame encoding or validation failure.
52 #[error("Frame error: {0}")]
53 Frame(#[from] uart_fpl::FrameError),
54 /// Go-Back-N retransmission attempts exceeded the protocol limit.
55 #[error("Retransmission limit exceeded: {0}")]
56 RetransmissionLimit(#[from] uart_fpl::RetransmissionLimitExceeded),
57 /// Received an unexpected sequence number while advancing the receiver window.
58 #[error("Unexpected sequence number: {0}")]
59 UnexpectedSeq(#[from] uart_fpl::UnexpectedSeqError),
60 /// Internal mpsc channel send failure between bridge tasks.
61 #[error("Internal channel communication error: {0}")]
62 ChannelSend(String),
63 /// Failed to connect to the target RCS `Connector` FIDL protocol.
64 #[error("Failed to connect to RCS Connector: {0}")]
65 RcsConnect(String),
66}
67
68/// Alias for results returned by the target UART driver.
69pub type Result<T, E = TargetDriverError> = std::result::Result<T, E>;