fbthrift_git/
errors.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use anyhow::Error;
18use thiserror::Error;
19
20use crate::ttype::TType;
21use crate::ApplicationException;
22
23#[derive(Debug, Error)]
24#[allow(dead_code)]
25pub enum ProtocolError {
26    #[error("end of file reached")]
27    EOF,
28    #[error("bad thrift version specified")]
29    BadVersion,
30    #[error("missing protocol version")]
31    ProtocolVersionMissing,
32    #[error("protocol skip depth exceeded")]
33    SkipDepthExceeded,
34    #[error("streams unsupported")]
35    StreamUnsupported,
36    #[error("STOP outside of struct in skip")]
37    UnexpectedStopInSkip,
38    #[error("Invalid type in skip {0:?}")]
39    InvalidTypeInSkip(TType),
40    #[error("Unknown or invalid protocol ID {0}")]
41    InvalidProtocolID(i16),
42    #[error("Unknown or invalid TMessage type {0}")]
43    InvalidMessageType(u32),
44    #[error("Unknown or invalid type tag")]
45    InvalidTypeTag,
46    #[error("Unknown or invalid data length")]
47    InvalidDataLength,
48    #[error("Invalid value for type")]
49    InvalidValue,
50    #[error("Unexpected trailing data after the end of a value")]
51    TrailingData,
52    #[error("Unwanted extra union {0} field ty {1:?} id {2}")]
53    UnwantedExtraUnionField(String, TType, i32),
54}
55
56/// Error value returned by functions that do not throw any user-defined exceptions.
57#[derive(Debug, Error)]
58pub enum NonthrowingFunctionError {
59    #[error(transparent)]
60    ApplicationException(#[from] ApplicationException),
61    #[error(transparent)]
62    ThriftError(#[from] Error),
63}