coap_zero/endpoint/
error.rs

1// Copyright Open Logistics Foundation
2//
3// Licensed under the Open Logistics Foundation License 1.3.
4// For details on the licensing terms, see the LICENSE file.
5// SPDX-License-Identifier: OLFL-1.3
6
7//! Error used by the CoAP-Zero [Endpoint](super::CoapEndpoint)
8//!
9//! Wraps underlying errors and defines own error cases that can occur in the Endpoint
10
11use crate::message;
12
13/// Endpoint Error
14///
15/// This error type only covers things that went wrong on our side and that the endpoint could not
16/// possibly handle in any meaningful way. For example, ill-formatted messages, messages arriving at
17/// the wrong time, messages which lack context or CoAP protocol timeouts are expected, handled
18/// automatically by the endpoint and only generate an "event" instead.
19#[derive(Debug)]
20pub enum Error<NetworkError> {
21    /// Could not get random number from given PRNG
22    Rng,
23    /// Endpoint is not connected
24    NotConnected,
25    /// Endpoint is already connected
26    AlreadyConnected,
27    /// Error while parsing the URI
28    Uri,
29    /// There is already an operation ongoing
30    Busy,
31    /// Something really weird went wrong
32    Impossible,
33    /// The method that was called is not available in the current state
34    Forbidden,
35    /// No data received
36    NoData,
37    /// Reset received
38    Reset,
39    /// Timeout during operation
40    Timeout,
41    /// Out of Memory
42    OutOfMemory,
43    /// Wrong message type was given
44    MessageType,
45    /// Network error from underlying UDP Stack
46    // TODO Depending on the perspective this may be an expected event, too
47    Network(NetworkError),
48    /// Error from [message] module
49    // TODO As far as I can tell, this can only happen when encoding a message which could be
50    // covered by OutOfMemory. For the decoding path, we map everything into events. We could
51    // change Message::encode to return a Result<..., ()> instead because OOM is the only error
52    // case that can happen there. But currently, it felt wrong to throw the message::Error from
53    // Message::encode away.
54    MessageError(message::Error),
55}
56
57impl<E> From<message::Error> for Error<E> {
58    fn from(e: message::Error) -> Self {
59        Error::MessageError(e)
60    }
61}