Skip to main content

astarte_device_sdk/store/
error.rs

1// This file is part of Astarte.
2//
3// Copyright 2023, 2026 SECO Mind Srl
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9//    http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// SPDX-License-Identifier: Apache-2.0
18
19//! Error for the store.
20
21use crate::error::DynError;
22
23/// Error that wraps the type returned by an implementation of the [`super::PropertyStore`] trait.
24#[non_exhaustive]
25#[derive(Debug, thiserror::Error)]
26pub enum StoreError {
27    /// Could not store a property.
28    #[error("could not store property")]
29    Store(#[source] DynError),
30    /// Could not update property state.
31    #[error("could not update property state")]
32    UpdateState(#[source] DynError),
33    /// Could not load a property.
34    #[error("could not load property")]
35    Load(#[source] DynError),
36    /// Could not delete a property.
37    #[error("could not delete property")]
38    Delete(#[source] DynError),
39    /// Could not unset a property.
40    #[error("could not delete property")]
41    Unset(#[source] DynError),
42    /// Could not clear the database.
43    #[error("could not clear database")]
44    Clear(#[source] DynError),
45    /// Could not load all properties.
46    #[error("could not load all properties")]
47    LoadAll(#[source] DynError),
48    /// Could not load device properties.
49    #[error("could not load device properties")]
50    DeviceProps(#[source] DynError),
51    /// Could not load server properties.
52    #[error("could not load server properties")]
53    ServerProps(#[source] DynError),
54    /// Could not load interface properties.
55    #[error("could not load server properties")]
56    InterfaceProps(#[source] DynError),
57    /// Could not delete all the interface properties.
58    #[error("could not delete all the interface properties")]
59    DeleteInterface(#[source] DynError),
60    /// Could not reset properties state
61    #[error("could not reset properties state")]
62    ResetState(#[source] DynError),
63}
64
65impl StoreError {
66    pub(crate) fn store(err: impl Into<DynError>) -> Self {
67        Self::Store(err.into())
68    }
69
70    pub(crate) fn update_state(err: impl Into<DynError>) -> Self {
71        Self::UpdateState(err.into())
72    }
73
74    pub(crate) fn load(err: impl Into<DynError>) -> Self {
75        Self::Load(err.into())
76    }
77
78    pub(crate) fn unset(err: impl Into<DynError>) -> Self {
79        Self::Unset(err.into())
80    }
81
82    pub(crate) fn delete(err: impl Into<DynError>) -> Self {
83        Self::Delete(err.into())
84    }
85
86    pub(crate) fn clear(err: impl Into<DynError>) -> Self {
87        Self::Clear(err.into())
88    }
89
90    pub(crate) fn load_all(err: impl Into<DynError>) -> Self {
91        Self::LoadAll(err.into())
92    }
93
94    pub(crate) fn server_props(err: impl Into<DynError>) -> Self {
95        Self::ServerProps(err.into())
96    }
97
98    pub(crate) fn device_props(err: impl Into<DynError>) -> Self {
99        Self::DeviceProps(err.into())
100    }
101
102    pub(crate) fn interface_props(err: impl Into<DynError>) -> Self {
103        Self::InterfaceProps(err.into())
104    }
105
106    pub(crate) fn delete_interface(err: impl Into<DynError>) -> Self {
107        Self::DeleteInterface(err.into())
108    }
109
110    pub(crate) fn reset_state(err: impl Into<DynError>) -> Self {
111        Self::ResetState(err.into())
112    }
113}