diff --git a/opendut-carl/opendut-carl-api/src/proto/services.rs b/opendut-carl/opendut-carl-api/src/proto/services.rs index 9db4797ce..496b89a80 100644 --- a/opendut-carl/opendut-carl-api/src/proto/services.rs +++ b/opendut-carl/opendut-carl-api/src/proto/services.rs @@ -38,7 +38,7 @@ pub mod cluster_manager { fn try_from(failure: CreateClusterConfigurationFailure) -> Result { type ErrorBuilder = ConversionErrorBuilder; let error = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; let error = match error { create_cluster_configuration_failure::Error::ClusterConfigurationAlreadyExists(error) => { error.try_into()? @@ -56,16 +56,16 @@ pub mod cluster_manager { fn try_from(failure: CreateClusterConfigurationFailureClusterConfigurationAlreadyExists) -> Result { type ErrorBuilder = ConversionErrorBuilder; let actual_id: ClusterId = failure.actual_id - .ok_or_else(|| ErrorBuilder::new("Field 'actual_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("actual_id"))? .try_into()?; let actual_name: ClusterName = failure.actual_name - .ok_or_else(|| ErrorBuilder::new("Field 'actual_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("actual_name"))? .try_into()?; let other_id: ClusterId = failure.other_id - .ok_or_else(|| ErrorBuilder::new("Field 'other_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("other_id"))? .try_into()?; let other_name: ClusterName = failure.other_name - .ok_or_else(|| ErrorBuilder::new("Field 'other_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("other_name"))? .try_into()?; Ok(CreateClusterConfigurationError::ClusterConfigurationAlreadyExists { actual_id, actual_name, other_id, other_name }) } @@ -76,10 +76,10 @@ pub mod cluster_manager { fn try_from(failure: CreateClusterConfigurationFailureInternal) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; let cluster_name: ClusterName = failure.cluster_name - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_name"))? .try_into()?; Ok(CreateClusterConfigurationError::Internal { cluster_id, cluster_name, cause: failure.cause }) } @@ -120,7 +120,7 @@ pub mod cluster_manager { fn try_from(failure: DeleteClusterConfigurationFailure) -> Result { type ErrorBuilder = ConversionErrorBuilder; let error = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; let error = match error { delete_cluster_configuration_failure::Error::ClusterConfigurationNotFound(error) => { error.try_into()? @@ -141,7 +141,7 @@ pub mod cluster_manager { fn try_from(failure: DeleteClusterConfigurationFailureClusterConfigurationNotFound) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; Ok(DeleteClusterConfigurationError::ClusterConfigurationNotFound { cluster_id }) } @@ -152,13 +152,13 @@ pub mod cluster_manager { fn try_from(failure: DeleteClusterConfigurationFailureIllegalClusterState) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; let cluster_name: ClusterName = failure.cluster_name - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_name"))? .try_into()?; let actual_state: ClusterState = failure.actual_state - .ok_or_else(|| ErrorBuilder::new("Field 'actual_state' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("actual_state"))? .try_into()?; let required_states = failure.required_states.into_iter() .map(proto::cluster::ClusterState::try_into) @@ -172,10 +172,10 @@ pub mod cluster_manager { fn try_from(failure: DeleteClusterConfigurationFailureInternal) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; let cluster_name: ClusterName = failure.cluster_name - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_name"))? .try_into()?; Ok(DeleteClusterConfigurationError::Internal { cluster_id, cluster_name, cause: failure.cause }) } @@ -211,7 +211,7 @@ pub mod cluster_manager { fn try_from(failure: StoreClusterDeploymentFailure) -> Result { type ErrorBuilder = ConversionErrorBuilder; let error = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; let error = match error { store_cluster_deployment_failure::Error::IllegalClusterState(error) => { error.try_into()? @@ -229,13 +229,13 @@ pub mod cluster_manager { fn try_from(failure: StoreClusterDeploymentFailureIllegalClusterState) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; let cluster_name: ClusterName = failure.cluster_name - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_name"))? .try_into()?; let actual_state: ClusterState = failure.actual_state - .ok_or_else(|| ErrorBuilder::new("Field 'actual_state' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("actual_state"))? .try_into()?; let required_states = failure.required_states.into_iter() .map(proto::cluster::ClusterState::try_into) @@ -249,10 +249,10 @@ pub mod cluster_manager { fn try_from(failure: StoreClusterDeploymentFailureInternal) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; let cluster_name: ClusterName = failure.cluster_name - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_name"))? .try_into()?; Ok(StoreClusterDeploymentError::Internal { cluster_id, cluster_name, cause: failure.cause }) } @@ -293,7 +293,7 @@ pub mod cluster_manager { fn try_from(failure: DeleteClusterDeploymentFailure) -> Result { type ErrorBuilder = ConversionErrorBuilder; let error = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; let error = match error { delete_cluster_deployment_failure::Error::ClusterDeploymentNotFound(error) => { error.try_into()? @@ -314,7 +314,7 @@ pub mod cluster_manager { fn try_from(failure: DeleteClusterDeploymentFailureClusterDeploymentNotFound) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; Ok(DeleteClusterDeploymentError::ClusterDeploymentNotFound { cluster_id }) } @@ -325,13 +325,13 @@ pub mod cluster_manager { fn try_from(failure: DeleteClusterDeploymentFailureIllegalClusterState) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; let cluster_name: ClusterName = failure.cluster_name - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_name"))? .try_into()?; let actual_state: ClusterState = failure.actual_state - .ok_or_else(|| ErrorBuilder::new("Field 'actual_state' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("actual_state"))? .try_into()?; let required_states = failure.required_states.into_iter() .map(proto::cluster::ClusterState::try_into) @@ -345,10 +345,10 @@ pub mod cluster_manager { fn try_from(failure: DeleteClusterDeploymentFailureInternal) -> Result { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: ClusterId = failure.cluster_id - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_id"))? .try_into()?; let cluster_name: ClusterName = failure.cluster_name - .ok_or_else(|| ErrorBuilder::new("Field 'cluster_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("cluster_name"))? .try_into()?; Ok(DeleteClusterDeploymentError::Internal { cluster_id, cluster_name, cause: failure.cause }) } @@ -409,7 +409,7 @@ pub mod peer_manager { fn try_from(failure: StorePeerDescriptorFailure) -> Result { type ErrorBuilder = ConversionErrorBuilder; let error = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; let error = match error { store_peer_descriptor_failure::Error::IllegalPeerState(error) => { error.try_into()? @@ -430,13 +430,13 @@ pub mod peer_manager { fn try_from(failure: StorePeerDescriptorFailureIllegalPeerState) -> Result { type ErrorBuilder = ConversionErrorBuilder; let peer_id: PeerId = failure.peer_id - .ok_or_else(|| ErrorBuilder::new("Field 'peer_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_id"))? .try_into()?; let peer_name: PeerName = failure.peer_name - .ok_or_else(|| ErrorBuilder::new("Field 'peer_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_name"))? .try_into()?; let actual_state: PeerState = failure.actual_state - .ok_or_else(|| ErrorBuilder::new("Field 'actual_state' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("actual_state"))? .try_into()?; let required_states = failure.required_states.into_iter() .map(proto::peer::PeerState::try_into) @@ -450,13 +450,13 @@ pub mod peer_manager { fn try_from(failure: StorePeerDescriptorFailureIllegalDevices) -> Result { type ErrorBuilder = ConversionErrorBuilder; let peer_id: PeerId = failure.peer_id - .ok_or_else(|| ErrorBuilder::new("Field 'peer_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_id"))? .try_into()?; let peer_name: PeerName = failure.peer_name - .ok_or_else(|| ErrorBuilder::new("Field 'peer_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_name"))? .try_into()?; let error: crate::carl::peer::IllegalDevicesError = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("error"))? .try_into()?; Ok(StorePeerDescriptorError::IllegalDevices { peer_id, peer_name, error }) } @@ -467,10 +467,10 @@ pub mod peer_manager { fn try_from(failure: StorePeerDescriptorFailureInternal) -> Result { type ErrorBuilder = ConversionErrorBuilder; let peer_id: PeerId = failure.peer_id - .ok_or_else(|| ErrorBuilder::new("Field 'peer_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_id"))? .try_into()?; let peer_name: PeerName = failure.peer_name - .ok_or_else(|| ErrorBuilder::new("Field 'peer_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_name"))? .try_into()?; Ok(StorePeerDescriptorError::Internal { peer_id, peer_name, cause: failure.cause }) } @@ -511,7 +511,7 @@ pub mod peer_manager { fn try_from(failure: DeletePeerDescriptorFailure) -> Result { type ErrorBuilder = ConversionErrorBuilder; let error = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; let error = match error { delete_peer_descriptor_failure::Error::PeerNotFound(error) => { error.try_into()? @@ -532,7 +532,7 @@ pub mod peer_manager { fn try_from(failure: DeletePeerDescriptorFailurePeerNotFound) -> Result { type ErrorBuilder = ConversionErrorBuilder; let peer_id: PeerId = failure.peer_id - .ok_or_else(|| ErrorBuilder::new("Field 'peer_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_id"))? .try_into()?; Ok(DeletePeerDescriptorError::PeerNotFound { peer_id }) } @@ -543,13 +543,13 @@ pub mod peer_manager { fn try_from(failure: DeletePeerDescriptorFailureIllegalPeerState) -> Result { type ErrorBuilder = ConversionErrorBuilder; let peer_id: PeerId = failure.peer_id - .ok_or_else(|| ErrorBuilder::new("Field 'peer_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_id"))? .try_into()?; let peer_name: PeerName = failure.peer_name - .ok_or_else(|| ErrorBuilder::new("Field 'peer_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_name"))? .try_into()?; let actual_state: PeerState = failure.actual_state - .ok_or_else(|| ErrorBuilder::new("Field 'actual_state' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("actual_state"))? .try_into()?; let required_states = failure.required_states.into_iter() .map(proto::peer::PeerState::try_into) @@ -563,10 +563,10 @@ pub mod peer_manager { fn try_from(failure: DeletePeerDescriptorFailureInternal) -> Result { type ErrorBuilder = ConversionErrorBuilder; let peer_id: PeerId = failure.peer_id - .ok_or_else(|| ErrorBuilder::new("Field 'peer_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_id"))? .try_into()?; let peer_name: PeerName = failure.peer_name - .ok_or_else(|| ErrorBuilder::new("Field 'peer_name' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_name"))? .try_into()?; Ok(DeletePeerDescriptorError::Internal { peer_id, peer_name, cause: failure.cause }) } @@ -591,7 +591,7 @@ pub mod peer_manager { fn try_from(error: IllegalDevicesError) -> Result { type ErrorBuilder = ConversionErrorBuilder; let inner = error.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; match inner { illegal_devices_error::Error::DeviceAlreadyExists(error) => { error.try_into() @@ -605,7 +605,7 @@ pub mod peer_manager { fn try_from(error: IllegalDevicesErrorDeviceAlreadyExists) -> Result { type ErrorBuilder = ConversionErrorBuilder; let device_id: DeviceId = error.device_id - .ok_or_else(|| ErrorBuilder::new("Field 'device_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("device_id"))? .try_into()?; Ok(crate::carl::peer::IllegalDevicesError::DeviceAlreadyExists { device_id }) } @@ -637,7 +637,7 @@ pub mod peer_manager { fn try_from(failure: GetPeerDescriptorFailure) -> Result { type ErrorBuilder = ConversionErrorBuilder; let error = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; let error = match error { get_peer_descriptor_failure::Error::PeerNotFound(error) => { error.try_into()? @@ -655,7 +655,7 @@ pub mod peer_manager { fn try_from(failure: GetPeerDescriptorFailurePeerNotFound) -> Result { type ErrorBuilder = ConversionErrorBuilder; let peer_id: PeerId = failure.peer_id - .ok_or_else(|| ErrorBuilder::new("Field 'peer_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_id"))? .try_into()?; Ok(GetPeerDescriptorError::PeerNotFound { peer_id }) } @@ -666,7 +666,7 @@ pub mod peer_manager { fn try_from(failure: GetPeerDescriptorFailureInternal) -> Result { type ErrorBuilder = ConversionErrorBuilder; let peer_id: PeerId = failure.peer_id - .ok_or_else(|| ErrorBuilder::new("Field 'peer_id' not set"))? + .ok_or_else(|| ErrorBuilder::field_not_set("peer_id"))? .try_into()?; Ok(GetPeerDescriptorError::Internal{ peer_id, cause: failure.cause}) } @@ -692,7 +692,7 @@ pub mod peer_manager { fn try_from(failure: ListPeerDescriptorsFailure) -> Result { type ErrorBuilder = ConversionErrorBuilder; let error = failure.error - .ok_or_else(|| ErrorBuilder::new("Field 'error' not set"))?; + .ok_or_else(|| ErrorBuilder::field_not_set("error"))?; let error = match error { list_peer_descriptors_failure::Error::Internal(error) => { error.try_into()? diff --git a/opendut-types/src/proto/cluster.rs b/opendut-types/src/proto/cluster.rs index 01e8cdb0b..4c856349c 100644 --- a/opendut-types/src/proto/cluster.rs +++ b/opendut-types/src/proto/cluster.rs @@ -18,7 +18,7 @@ impl TryFrom for crate::cluster::ClusterId { type ErrorBuilder = ConversionErrorBuilder; value.uuid - .ok_or(ErrorBuilder::new("Uuid not set")) + .ok_or(ErrorBuilder::field_not_set("uuid")) .map(|uuid| Self(uuid.into())) } } @@ -46,7 +46,7 @@ impl TryFrom for crate::cluster::ClusterName { type ErrorBuilder = ConversionErrorBuilder; crate::cluster::ClusterName::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -70,15 +70,15 @@ impl TryFrom for crate::cluster::ClusterConfiguration { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: crate::cluster::ClusterId = configuration.id - .ok_or(ErrorBuilder::new("Id not set"))? + .ok_or(ErrorBuilder::field_not_set("id"))? .try_into()?; let cluster_name: crate::cluster::ClusterName = configuration.name - .ok_or(ErrorBuilder::new("Name not set"))? + .ok_or(ErrorBuilder::field_not_set("name"))? .try_into()?; let leader: crate::peer::PeerId = configuration.leader - .ok_or(ErrorBuilder::new("Leader not set"))? + .ok_or(ErrorBuilder::field_not_set("leader"))? .try_into()?; Ok(Self { @@ -107,7 +107,7 @@ impl TryFrom for crate::cluster::ClusterDeployment { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: crate::cluster::ClusterId = deployment.id - .ok_or(ErrorBuilder::new("Id not set"))? + .ok_or(ErrorBuilder::field_not_set("id"))? .try_into()?; Ok(Self { @@ -158,7 +158,7 @@ impl TryFrom for crate::cluster::state::ClusterState { type ErrorBuilder = ConversionErrorBuilder; let inner = state.inner - .ok_or(ErrorBuilder::new("Inner state not set"))?; + .ok_or(ErrorBuilder::field_not_set("inner"))?; match inner { cluster_state::Inner::Undeployed(_) => { @@ -169,7 +169,7 @@ impl TryFrom for crate::cluster::state::ClusterState { } cluster_state::Inner::Deployed(state) => { let inner = state.inner - .ok_or(ErrorBuilder::new("Inner state not set"))?; + .ok_or(ErrorBuilder::field_not_set("inner"))?; let inner = match inner { cluster_state_deployed::Inner::Unhealthy(_) => { crate::cluster::state::DeployedClusterState::Unhealthy @@ -200,11 +200,11 @@ impl TryFrom for crate::cluster::ClusterAssignment { type ErrorBuilder = ConversionErrorBuilder; let cluster_id: crate::cluster::ClusterId = value.id - .ok_or(ErrorBuilder::new("field 'id' not set"))? + .ok_or(ErrorBuilder::field_not_set("id"))? .try_into()?; let leader: crate::peer::PeerId = value.leader - .ok_or(ErrorBuilder::new("field 'leader' not set"))? + .ok_or(ErrorBuilder::field_not_set("leader"))? .try_into()?; let assignments: Vec = value.assignments @@ -237,15 +237,15 @@ impl TryFrom for crate::cluster::PeerClusterAssignment { type ErrorBuilder = ConversionErrorBuilder; let peer_id: crate::peer::PeerId = value.peer_id - .ok_or(ErrorBuilder::new("field 'peer_id' not set"))? + .ok_or(ErrorBuilder::field_not_set("peer_id"))? .try_into()?; let vpn_address: std::net::IpAddr = value.vpn_address - .ok_or(ErrorBuilder::new("field 'vpn_address' not set"))? + .ok_or(ErrorBuilder::field_not_set("vpn_address"))? .try_into()?; let can_server_port: crate::util::Port = value.can_server_port - .ok_or(ErrorBuilder::new("field 'can_server_port' not set"))? + .ok_or(ErrorBuilder::field_not_set("can_server_port"))? .try_into()?; let device_interfaces: Vec = value.device_interfaces diff --git a/opendut-types/src/proto/mod.rs b/opendut-types/src/proto/mod.rs index 2ef8f33c5..6a126473b 100644 --- a/opendut-types/src/proto/mod.rs +++ b/opendut-types/src/proto/mod.rs @@ -31,7 +31,11 @@ pub struct ConversionErrorBuilder { #[allow(clippy::new_ret_no_self)] impl ConversionErrorBuilder { - pub fn new(details: impl Into) -> ConversionError { + pub fn message(details: impl Into) -> ConversionError { + ConversionError::new::(details) + } + pub fn field_not_set(field: impl Into) -> ConversionError { + let details = format!("Field '{}' not set", field.into()); ConversionError::new::(details) } } diff --git a/opendut-types/src/proto/peer/configuration.rs b/opendut-types/src/proto/peer/configuration.rs index c9bc4c7e5..351ee1690 100644 --- a/opendut-types/src/proto/peer/configuration.rs +++ b/opendut-types/src/proto/peer/configuration.rs @@ -18,7 +18,7 @@ impl TryFrom for crate::peer::configuration::PeerConfiguratio type ErrorBuilder = ConversionErrorBuilder; let executors = value.executors - .ok_or(ErrorBuilder::new("Executor not set"))? + .ok_or(ErrorBuilder::field_not_set("executors"))? .try_into()?; let cluster_assignment = value.cluster_assignment diff --git a/opendut-types/src/proto/peer/executor.rs b/opendut-types/src/proto/peer/executor.rs index a60634b73..2a4c554a9 100644 --- a/opendut-types/src/proto/peer/executor.rs +++ b/opendut-types/src/proto/peer/executor.rs @@ -75,7 +75,7 @@ impl TryFrom for crate::peer::executor::ExecutorDescriptor { type ErrorBuilder = ConversionErrorBuilder; let descriptor = value.descriptor - .ok_or(ErrorBuilder::new("Executor not set not set"))?; + .ok_or(ErrorBuilder::field_not_set("descriptor"))?; let result = match descriptor { executor_descriptor::Descriptor::Executable(_) => { @@ -94,13 +94,13 @@ impl TryFrom for crate::peer::executor::ExecutorDescriptor { args } = descriptor; let engine = engine - .ok_or(ErrorBuilder::new("Engine not set"))? + .ok_or(ErrorBuilder::field_not_set("engine"))? .try_into()?; let name = name - .ok_or(ErrorBuilder::new("Container Name not set"))? + .ok_or(ErrorBuilder::field_not_set("name"))? .try_into()?; let image = image - .ok_or(ErrorBuilder::new("Container Image not set"))? + .ok_or(ErrorBuilder::field_not_set("image"))? .try_into()?; let volumes = volumes .into_iter() @@ -119,7 +119,7 @@ impl TryFrom for crate::peer::executor::ExecutorDescriptor { .map(TryFrom::try_from) .collect::>()?; let command = command - .ok_or(ErrorBuilder::new("Container Command not set"))? + .ok_or(ErrorBuilder::field_not_set("command"))? .try_into()?; let args = args .into_iter() @@ -171,7 +171,7 @@ impl TryFrom for crate::peer::executor::Engine { type ErrorBuilder = ConversionErrorBuilder; let inner = value.inner - .ok_or(ErrorBuilder::new("Engine not set"))?; + .ok_or(ErrorBuilder::field_not_set("inner"))?; let result = match inner { engine::Inner::Docker(_) => { @@ -202,7 +202,7 @@ impl TryFrom for crate::peer::executor::ContainerName { type ErrorBuilder = ConversionErrorBuilder; crate::peer::executor::ContainerName::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -221,7 +221,7 @@ impl TryFrom for crate::peer::executor::ContainerImage { type ErrorBuilder = ConversionErrorBuilder; crate::peer::executor::ContainerImage::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -240,7 +240,7 @@ impl TryFrom for crate::peer::executor::ContainerVolume { type ErrorBuilder = ConversionErrorBuilder; crate::peer::executor::ContainerVolume::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -259,7 +259,7 @@ impl TryFrom for crate::peer::executor::ContainerDevice { type ErrorBuilder = ConversionErrorBuilder; crate::peer::executor::ContainerDevice::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -280,7 +280,7 @@ impl TryFrom for crate::peer::executor::ContainerE type ErrorBuilder = ConversionErrorBuilder; crate::peer::executor::ContainerEnvironmentVariable::new(value.name, value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -299,7 +299,7 @@ impl TryFrom for crate::peer::executor::ContainerPortSpec { type ErrorBuilder = ConversionErrorBuilder; crate::peer::executor::ContainerPortSpec::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -310,7 +310,7 @@ impl TryFrom for crate::peer::executor::ContainerCommand { type ErrorBuilder = ConversionErrorBuilder; crate::peer::executor::ContainerCommand::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -337,6 +337,6 @@ impl TryFrom for crate::peer::executor::ContainerComma type ErrorBuilder = ConversionErrorBuilder; crate::peer::executor::ContainerCommandArgument::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } -} \ No newline at end of file +} diff --git a/opendut-types/src/proto/peer/mod.rs b/opendut-types/src/proto/peer/mod.rs index 7ae44c7ca..4c3615299 100644 --- a/opendut-types/src/proto/peer/mod.rs +++ b/opendut-types/src/proto/peer/mod.rs @@ -24,7 +24,7 @@ impl TryFrom for crate::peer::PeerId { type ErrorBuilder = ConversionErrorBuilder; value.uuid - .ok_or(ErrorBuilder::new("Uuid not set")) + .ok_or(ErrorBuilder::field_not_set("uuid")) .map(|uuid| Self(uuid.into())) } } @@ -53,7 +53,7 @@ impl TryFrom for crate::peer::PeerName { type ErrorBuilder = ConversionErrorBuilder; crate::peer::PeerName::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -80,7 +80,7 @@ impl TryFrom for crate::peer::PeerLocation { type ErrorBuilder = ConversionErrorBuilder; crate::peer::PeerLocation::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -129,11 +129,11 @@ impl TryFrom for crate::peer::PeerDescriptor { type ErrorBuilder = ConversionErrorBuilder; let id = value.id - .ok_or(ErrorBuilder::new("Id not set"))? + .ok_or(ErrorBuilder::field_not_set("id"))? .try_into()?; let name = value.name - .ok_or(ErrorBuilder::new("Name not set"))? + .ok_or(ErrorBuilder::field_not_set("name"))? .try_into()?; let location = value.location @@ -141,15 +141,15 @@ impl TryFrom for crate::peer::PeerDescriptor { .transpose()?; let network_configuration = value.network_configuration - .ok_or(ErrorBuilder::new("Network configuration not set"))? + .ok_or(ErrorBuilder::field_not_set("network_configuration"))? .try_into()?; let topology = value.topology - .ok_or(ErrorBuilder::new("Topology not set"))? + .ok_or(ErrorBuilder::field_not_set("topology"))? .try_into()?; let executors = value.executors - .ok_or(ErrorBuilder::new("Executor not set"))? + .ok_or(ErrorBuilder::field_not_set("executors"))? .try_into()?; Ok(crate::peer::PeerDescriptor { @@ -182,24 +182,24 @@ impl TryFrom for crate::peer::PeerSetup { type ErrorBuilder = ConversionErrorBuilder; let id: crate::peer::PeerId = value.id - .ok_or(ErrorBuilder::new("PeerId not set"))? + .ok_or(ErrorBuilder::field_not_set("id"))? .try_into()?; let carl: url::Url = value.carl - .ok_or(ErrorBuilder::new("Carl not set")) + .ok_or(ErrorBuilder::field_not_set("carl")) .and_then(|url| url::Url::parse(&url.value) - .map_err(|cause| ErrorBuilder::new(format!("Carl URL could not be parsed: {}", cause))))?; + .map_err(|cause| ErrorBuilder::message(format!("Carl URL could not be parsed: {}", cause))))?; let ca: crate::util::net::Certificate = value.ca - .ok_or(ErrorBuilder::new("No CA Certificate provided.")) + .ok_or(ErrorBuilder::field_not_set("ca")) .and_then(crate::util::net::Certificate::try_from)?; let vpn: crate::vpn::VpnPeerConfiguration = value.vpn - .ok_or(ErrorBuilder::new("VpnConfig not set")) + .ok_or(ErrorBuilder::field_not_set("vpn")) .and_then(VpnPeerConfig::try_into)?; let auth_config = value.auth_config - .ok_or(ErrorBuilder::new("PeerId not set"))? + .ok_or(ErrorBuilder::field_not_set("auth_config"))? .try_into()?; Ok(Self { @@ -282,7 +282,7 @@ impl TryFrom for crate::peer::state::PeerState { type ErrorBuilder = ConversionErrorBuilder; let inner = state.inner - .ok_or(ErrorBuilder::new("Inner state not set"))?; + .ok_or(ErrorBuilder::field_not_set("inner"))?; match inner { peer_state::Inner::Down(_) => { @@ -291,12 +291,12 @@ impl TryFrom for crate::peer::state::PeerState { peer_state::Inner::Up(PeerStateUp { inner, remote_host }) => { let remote_host: std::net::IpAddr = remote_host - .ok_or(ErrorBuilder::new("field 'remote_host' not set"))? + .ok_or(ErrorBuilder::field_not_set("remote_host"))? .try_into()?; let inner = inner - .ok_or(ErrorBuilder::new("Inner 'Up' state not set"))?; + .ok_or(ErrorBuilder::message("Inner 'Up' state not set"))?; match inner { peer_state_up::Inner::Available(_) => { @@ -308,7 +308,7 @@ impl TryFrom for crate::peer::state::PeerState { peer_state_up::Inner::Blocked(PeerStateUpBlocked { inner }) => { let inner = inner - .ok_or(ErrorBuilder::new("Inner 'Blocked' state not set"))?; + .ok_or(ErrorBuilder::message("Inner 'Blocked' state not set"))?; match inner { peer_state_up_blocked::Inner::Deploying(_) => { diff --git a/opendut-types/src/proto/topology.rs b/opendut-types/src/proto/topology.rs index aefc377e6..de48e6f3b 100644 --- a/opendut-types/src/proto/topology.rs +++ b/opendut-types/src/proto/topology.rs @@ -18,7 +18,7 @@ impl TryFrom for crate::topology::DeviceId { value .uuid - .ok_or(ErrorBuilder::new("Uuid not set")) + .ok_or(ErrorBuilder::field_not_set("uuid")) .map(|uuid| Self(uuid.into())) } } @@ -71,7 +71,7 @@ impl TryFrom for crate::topology::DeviceName { type ErrorBuilder = ConversionErrorBuilder; crate::topology::DeviceName::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -83,7 +83,7 @@ impl TryFrom for crate::topology::DeviceDescription { ConversionErrorBuilder; crate::topology::DeviceDescription::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -94,7 +94,7 @@ impl TryFrom for crate::topology::DeviceTag { type ErrorBuilder = ConversionErrorBuilder; crate::topology::DeviceTag::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -135,17 +135,17 @@ impl TryFrom for crate::topology::DeviceDescriptor { let device_id: crate::topology::DeviceId = value .id - .ok_or(ErrorBuilder::new("Id not set"))? + .ok_or(ErrorBuilder::field_not_set("id"))? .try_into()?; let device_name: crate::topology::DeviceName = value .name - .ok_or(ErrorBuilder::new("Name not set"))? + .ok_or(ErrorBuilder::field_not_set("name"))? .try_into()?; let device_description: Option = value.description.map(TryFrom::try_from).transpose()?; let interface: crate::util::net::NetworkInterfaceDescriptor = value .interface - .ok_or(ErrorBuilder::new("Interface not set"))? + .ok_or(ErrorBuilder::field_not_set("interface"))? .try_into()?; let device_tags: Vec = value .tags @@ -307,7 +307,7 @@ mod tests { err(eq(ConversionError::new::< DeviceDescriptor, crate::topology::DeviceDescriptor, - >("Id not set"))) + >("Field 'id' not set"))) )?; Ok(()) diff --git a/opendut-types/src/proto/util.rs b/opendut-types/src/proto/util.rs index a5aec4b39..cd05cc917 100644 --- a/opendut-types/src/proto/util.rs +++ b/opendut-types/src/proto/util.rs @@ -58,7 +58,7 @@ impl TryFrom for u16 { value.value .try_into() - .map_err(|_| ErrorBuilder::new("Port value is out of range")) + .map_err(|_| ErrorBuilder::message("Port value is out of range")) } } @@ -76,7 +76,7 @@ impl TryFrom for util::Port { let port: u16 = value.value .try_into() - .map_err(|_| ErrorBuilder::new("Port value is out of range"))?; + .map_err(|_| ErrorBuilder::message("Port value is out of range"))?; Ok(util::Port(port)) } @@ -95,7 +95,7 @@ impl TryFrom for url::Url { type ErrorBuilder = ConversionErrorBuilder; url::Url::parse(&value.value) - .map_err(|cause| ErrorBuilder::new(format!("Url could not be parsed: {}", cause))) + .map_err(|cause| ErrorBuilder::message(format!("Url could not be parsed: {}", cause))) } } @@ -118,16 +118,16 @@ impl TryFrom for std::net::IpAddr { type ErrorBuilder = ConversionErrorBuilder; let address = value.address - .ok_or(ErrorBuilder::new("IP address not set"))?; + .ok_or(ErrorBuilder::field_not_set("address"))?; let address = match address { Address::IpV4(address) => std::net::IpAddr::V4( std::net::Ipv4Addr::try_from(address) - .map_err(|cause| ErrorBuilder::new(cause.to_string()))? + .map_err(|cause| ErrorBuilder::message(cause.to_string()))? ), Address::IpV6(address) => std::net::IpAddr::V6( std::net::Ipv6Addr::try_from(address) - .map_err(|cause| ErrorBuilder::new(cause.to_string()))? + .map_err(|cause| ErrorBuilder::message(cause.to_string()))? ), }; Ok(address) @@ -150,7 +150,7 @@ impl TryFrom for std::net::Ipv4Addr { const IPV4_LENGTH: usize = 4; //bytes let octets: [u8; IPV4_LENGTH] = value.value[0..IPV4_LENGTH].try_into() - .map_err(|cause| ErrorBuilder::new(format!("IPv4 address could not be parsed, because it did not have the correct length ({IPV4_LENGTH} bytes): {}", cause)))?; + .map_err(|cause| ErrorBuilder::message(format!("IPv4 address could not be parsed, because it did not have the correct length ({IPV4_LENGTH} bytes): {}", cause)))?; Ok(std::net::Ipv4Addr::from(octets)) } @@ -172,7 +172,7 @@ impl TryFrom for std::net::Ipv6Addr { const IPV6_LENGTH: usize = 16; //bytes let octets: [u8; IPV6_LENGTH] = value.value[0..IPV6_LENGTH].try_into() - .map_err(|cause| ErrorBuilder::new(format!("IPv6 address could not be parsed, because it did not have the correct length ({IPV6_LENGTH} bytes): {}", cause)))?; + .map_err(|cause| ErrorBuilder::message(format!("IPv6 address could not be parsed, because it did not have the correct length ({IPV6_LENGTH} bytes): {}", cause)))?; Ok(std::net::Ipv6Addr::from(octets)) } @@ -192,7 +192,7 @@ impl TryFrom for crate::util::net::NetworkInterfaceName { type ErrorBuilder = ConversionErrorBuilder; crate::util::net::NetworkInterfaceName::try_from(value.name) - .map_err(|cause| ErrorBuilder::new(format!("Failed to parse InterfaceName from proto: {cause}"))) + .map_err(|cause| ErrorBuilder::message(format!("Failed to parse InterfaceName from proto: {cause}"))) } } @@ -247,20 +247,20 @@ impl TryFrom for crate::util::net::NetworkInterfaceD type ErrorBuilder = ConversionErrorBuilder; let name = value.name - .ok_or(ErrorBuilder::new("Interface not set"))? + .ok_or(ErrorBuilder::field_not_set("interface"))? .try_into()?; let configuration = match value.configuration - .ok_or(ErrorBuilder::new("Configuration not set"))? { + .ok_or(ErrorBuilder::field_not_set("configuration"))? { network_interface_descriptor::Configuration::Ethernet(_) => NetworkInterfaceConfiguration::Ethernet, network_interface_descriptor::Configuration::Can(can_config) => NetworkInterfaceConfiguration::Can { bitrate: can_config.bitrate, sample_point: can_config.sample_point.try_into() - .map_err(|cause| ErrorBuilder::new(format!("Sample point could not be converted: {}", cause)))?, + .map_err(|cause| ErrorBuilder::message(format!("Sample point could not be converted: {}", cause)))?, fd: can_config.flexible_data_rate, data_bitrate: can_config.data_bitrate, data_sample_point: can_config.data_sample_point.try_into() - .map_err(|cause| ErrorBuilder::new(format!("Sample point could not be converted: {}", cause)))?, + .map_err(|cause| ErrorBuilder::message(format!("Sample point could not be converted: {}", cause)))?, }, }; @@ -287,7 +287,7 @@ impl TryFrom for crate::util::net::ClientSecret { type ErrorBuilder = ConversionErrorBuilder; crate::util::net::ClientSecret::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -306,7 +306,7 @@ impl TryFrom for crate::util::net::ClientId { type ErrorBuilder = ConversionErrorBuilder; crate::util::net::ClientId::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -326,7 +326,7 @@ impl TryFrom for crate::util::net::OAuthScope { type ErrorBuilder = ConversionErrorBuilder; crate::util::net::OAuthScope::try_from(value.value) - .map_err(|cause| ErrorBuilder::new(cause.to_string())) + .map_err(|cause| ErrorBuilder::message(cause.to_string())) } } @@ -361,21 +361,21 @@ impl TryFrom for crate::util::net::AuthConfig { type ErrorBuilder = ConversionErrorBuilder; let config = match value.config - .ok_or(ErrorBuilder::new("Configuration not set"))? { + .ok_or(ErrorBuilder::field_not_set("configuration"))? { Config::Disabled(_) => crate::util::net::AuthConfig::Disabled, Config::Enabled(auth_config) => { let issuer_url = auth_config.issuer_url - .ok_or(ErrorBuilder::new("Authorization Provider Issuer URL not set")) + .ok_or(ErrorBuilder::message("Authorization Provider Issuer URL not set")) .and_then(|url| url::Url::parse(&url.value) - .map_err(|cause| ErrorBuilder::new(format!("Authorization Provider Issuer URL could not be parsed: {}", cause))) + .map_err(|cause| ErrorBuilder::message(format!("Authorization Provider Issuer URL could not be parsed: {}", cause))) )?; let client_id: crate::util::net::ClientId = auth_config.client_id - .ok_or(ErrorBuilder::new("ClientId not set"))? + .ok_or(ErrorBuilder::field_not_set("client_id"))? .try_into()?; let client_secret: crate::util::net::ClientSecret = auth_config.client_secret - .ok_or(ErrorBuilder::new("ClientSecret not set"))? + .ok_or(ErrorBuilder::field_not_set("client_secret"))? .try_into()?; let scopes: Vec = auth_config diff --git a/opendut-types/src/proto/vpn.rs b/opendut-types/src/proto/vpn.rs index 1fc4ed62d..f26494150 100644 --- a/opendut-types/src/proto/vpn.rs +++ b/opendut-types/src/proto/vpn.rs @@ -33,7 +33,7 @@ impl TryFrom for crate::vpn::VpnPeerConfiguration { type ErrorBuilder = ConversionErrorBuilder; let config = value.config - .ok_or(ErrorBuilder::new("Config not set"))?; + .ok_or(ErrorBuilder::field_not_set("config"))?; let result = match config { vpn_peer_config::Config::Disabled(_) => { @@ -42,10 +42,10 @@ impl TryFrom for crate::vpn::VpnPeerConfiguration { vpn_peer_config::Config::Netbird(config) => { let VpnPeerConfigNetbird { management_url, setup_key } = config; let management_url = management_url - .ok_or(ErrorBuilder::new("Management URL not set"))? + .ok_or(ErrorBuilder::field_not_set("management_url"))? .try_into()?; let setup_key = setup_key - .ok_or(ErrorBuilder::new("Setup Key not set"))? + .ok_or(ErrorBuilder::field_not_set("setup_key"))? .try_into()?; crate::vpn::VpnPeerConfiguration::Netbird { management_url, @@ -71,7 +71,7 @@ impl TryFrom for crate::vpn::netbird::SetupKey { type ErrorBuilder = ConversionErrorBuilder; let uuid: uuid::Uuid = value.uuid - .ok_or(ErrorBuilder::new("Setup Key UUID not set"))? + .ok_or(ErrorBuilder::field_not_set("uuid"))? .into(); let result = crate::vpn::netbird::SetupKey::from(uuid); Ok(result)