Skip to main content

fidl_next_codec/encode/
error.rs

1// Copyright 2024 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::ValidationError;
8
9/// Errors that can be produced while encoding FIDL messages.
10#[derive(Clone, Error, Debug, PartialEq)]
11pub enum EncodeError {
12    /// A required handle was invalid.
13    #[error("required handle was invalid")]
14    InvalidRequiredHandle,
15
16    /// An encoded union had an unknown ordinal
17    #[error("cannot encode unknown union ordinal of {0}")]
18    UnknownUnionOrdinal(usize),
19
20    /// Attempted to encode a value larger than 4 bytes in an inline envelope
21    #[error("cannot encode a {0}-byte value in a 4-byte inline envelope")]
22    ExpectedInline(usize),
23
24    /// Attempted to encode a driver handle with an encoder that does not support them.
25    #[error("cannot encode driver handles with this encoder")]
26    DriverHandlesUnsupported,
27
28    /// Expected a driver handle but was given a normal zircon handle
29    #[error("expected a driver handle but was given a zircon handle")]
30    ExpectedDriverHandle,
31
32    /// Expected a zircon handle but was given a driver handle
33    #[error("expected a zircon handle but was given a driver handle")]
34    ExpectedZirconHandle,
35
36    /// Invalid bits were set in a strict bits value.
37    #[error("invalid bits were set in a strict bits value")]
38    InvalidStrictBits,
39
40    /// Validation Failed
41    #[error("validation failed")]
42    Validation(#[from] ValidationError),
43}