1 // Copyright 2022, The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //! This module defines the error type and the result type for this library. 16 17 /// The error type for the uwb_core library. 18 #[non_exhaustive] // Adding new enum fields doesn't break the downstream build. 19 #[derive(Clone, Debug, thiserror::Error, PartialEq, Eq)] 20 pub enum Error { 21 /// The provided parameters are invalid, or the method is not allowed to be called in the 22 /// current state. 23 #[error("Bad parameters")] 24 BadParameters, 25 /// Error across Foreign Function Interface. 26 #[error("Error across Foreign Function Interface")] 27 ForeignFunctionInterface, 28 /// The maximum number of sessions has been reached. 29 #[error("The maximum number of sessions has been reached")] 30 MaxSessionsExceeded, 31 /// Max ranging round retries reached. 32 #[error("Max ranging round retries reached")] 33 MaxRrRetryReached, 34 /// Fails due to a protocol specific reason. 35 #[error("The session fails with a protocol specific reason")] 36 ProtocolSpecific, 37 /// The remote device has requested to change the session. 38 #[error("The remote device has requested to change the session")] 39 RemoteRequest, 40 /// The response or notification is not received in timeout. 41 #[error("The response or notification is not received in timeout")] 42 Timeout, 43 /// The command should be retried. 44 #[error("The command should be retried")] 45 CommandRetry, 46 /// Duplicated SessionId. 47 #[error("Duplicated SessionId")] 48 DuplicatedSessionId, 49 /// Packet Tx Error 50 #[error("The packet send failed with an error")] 51 PacketTxError, 52 /// Country code regulation UWB Off 53 #[error("The country code command failed with a UWB regulatory error")] 54 RegulationUwbOff, 55 /// The unknown error. 56 #[error("The unknown error")] 57 Unknown, 58 59 /// The result of the mock method is not assigned 60 #[cfg(any(test, feature = "mock-utils"))] 61 #[error("The result of the mock method is not assigned")] 62 MockUndefined, 63 } 64 65 /// The result type for the uwb_core library. 66 /// 67 /// This type is broadly used by the methods in this library which may produce an error. 68 pub type Result<T> = std::result::Result<T, Error>; 69