From 5e1fe21668334a6b5148a75e18fd02093bebe86c Mon Sep 17 00:00:00 2001 From: Olivier Date: Thu, 2 Jan 2025 18:10:22 +0100 Subject: [PATCH] add custom errors compatible with std to be used for internal code and not abuse StatusCode errors from protocol --- Cargo.lock | 1 + opcua-core/Cargo.toml | 1 + opcua-core/src/errors.rs | 12 ++++++++++++ opcua-core/src/lib.rs | 3 +++ samples/client.conf | 20 ++++++++++---------- 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 opcua-core/src/errors.rs diff --git a/Cargo.lock b/Cargo.lock index 0556d0633..34b1afb27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1215,6 +1215,7 @@ dependencies = [ "parking_lot", "serde", "serde_yaml", + "thiserror", "tokio", "tokio-util", "url", diff --git a/opcua-core/Cargo.toml b/opcua-core/Cargo.toml index 34bfc79bd..e062396ec 100644 --- a/opcua-core/Cargo.toml +++ b/opcua-core/Cargo.toml @@ -28,6 +28,7 @@ url = { workspace = true } opcua-types = { path = "../opcua-types" } opcua-crypto = { path = "../opcua-crypto" } +thiserror.workspace = true [lints.rust] diff --git a/opcua-core/src/errors.rs b/opcua-core/src/errors.rs new file mode 100644 index 000000000..070bb020b --- /dev/null +++ b/opcua-core/src/errors.rs @@ -0,0 +1,12 @@ +use opcua_types::{Variant, VariantScalarTypeId}; +use thiserror::Error; + +/// Rust OpcUa specific errors +#[allow(missing_docs)] +#[derive(Error, Debug)] +pub enum OpcUAError { + #[error("Received an expected variant type")] + UnExpectedVariantType(Option