Skip to main content

twine_codec/
error.rs

1// Copyright (c) 2025 Jake Swensen
2// SPDX-License-Identifier: MPL-2.0
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8use thiserror::Error;
9
10use twine_tlv::TwineTlvError;
11
12#[derive(Debug, Error, PartialEq)]
13pub enum TwineCodecError {
14    #[error("Could not convert buffer of bytes to {0}")]
15    BufferBytesConversion(&'static str),
16
17    #[error("Buffer was too short to begin decoding")]
18    BufferDecodeTooShort,
19
20    #[error("Unexpected length when parsing a TLV. Expected {0}; Found {1}")]
21    BufferDecodeUnexpectedTlvLength(usize, usize),
22
23    #[error("No space left in the buffer to write data")]
24    BufferEncodeNoSpace,
25
26    #[error("Provided value length exceeds TLV maximum")]
27    BufferEncodeMaxLength,
28
29    #[error("Number of bytes exceeds buffer maximum length; expected {0}, found {1}")]
30    BufferMaxLength(usize, usize),
31
32    #[error("TLV type mismatch")]
33    BufferTlvWrongType,
34
35    #[error("Hex decode error")]
36    HexDecodeError,
37
38    #[error("Missing dataset parameter: {0}")]
39    MissingDatasetParameter(&'static str),
40
41    #[error("String parse error")]
42    StringParseError,
43
44    #[error(transparent)]
45    TlvError(#[from] TwineTlvError),
46
47    #[error("Could not build {0}")]
48    TypeBuildError(&'static str),
49
50    #[error("{0}")]
51    Internal(&'static str),
52}