opcua_types/
errors.rs

1// OPCUA for Rust
2// SPDX-License-Identifier: MPL-2.0
3
4//!  Rust OpcUa specific errors
5
6use thiserror::Error;
7
8use crate::{relative_path::RelativePathError, StatusCode, VariantScalarTypeId};
9
10/// Rust OpcUa specific errors
11#[allow(missing_docs)]
12#[derive(Error, Debug)]
13pub enum OpcUaError {
14    #[error("Received an unexpected variant type")]
15    UnexpectedVariantType {
16        variant_id: Option<VariantScalarTypeId>,
17        message: String,
18    },
19    #[error("The requested namespace does not exists")]
20    NamespaceDoesNotExist(String),
21    #[error("Request returned a StatusCode Error: {0}")]
22    StatusCodeError(StatusCode),
23    #[error("Generic Error: {0}")]
24    Error(crate::Error),
25    #[error("Function returned a RelativePathError: {0}")]
26    RelativePathError(RelativePathError),
27}
28
29impl From<StatusCode> for OpcUaError {
30    fn from(value: StatusCode) -> Self {
31        OpcUaError::StatusCodeError(value)
32    }
33}
34
35impl From<crate::Error> for OpcUaError {
36    fn from(value: crate::Error) -> Self {
37        OpcUaError::Error(value)
38    }
39}
40
41impl From<RelativePathError> for OpcUaError {
42    fn from(value: RelativePathError) -> Self {
43        OpcUaError::RelativePathError(value)
44    }
45}