From eda5753bb93558718ad6a04f92e2391515e7886a Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Tue, 14 Feb 2023 14:32:49 +0000 Subject: [PATCH] Improve error messages. Fix gateway_id is missing ... errors. The error would occur when the uplink was also received by an unknown gateway. In this case fetching the metadata for this gateway would fail, causing the gateway_private_up and _down not to be populated with the gateway_id. --- chirpstack/src/downlink/helpers.rs | 4 +++- chirpstack/src/uplink/data.rs | 2 +- chirpstack/src/uplink/join.rs | 2 +- chirpstack/src/uplink/mod.rs | 12 +++++++----- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/chirpstack/src/downlink/helpers.rs b/chirpstack/src/downlink/helpers.rs index affb5d59..9a0a84b5 100644 --- a/chirpstack/src/downlink/helpers.rs +++ b/chirpstack/src/downlink/helpers.rs @@ -46,7 +46,9 @@ pub fn select_downlink_gateway( .collect(); if rx_info.items.is_empty() { - return Err(anyhow!("rx_info.items can not be empty")); + return Err(anyhow!( + "RxInfo set is empty after applying filters, no downlink gateway available" + )); } let region_conf = region::get(region_config_id)?; diff --git a/chirpstack/src/uplink/data.rs b/chirpstack/src/uplink/data.rs index 9a4c622a..8ce0da70 100644 --- a/chirpstack/src/uplink/data.rs +++ b/chirpstack/src/uplink/data.rs @@ -407,7 +407,7 @@ impl Data { trace!("Filtering rx_info by tenant_id"); match filter_rx_info_by_tenant_id( - &self.application.as_ref().unwrap().tenant_id, + self.application.as_ref().unwrap().tenant_id, &mut self.uplink_frame_set, ) { Ok(_) => Ok(()), diff --git a/chirpstack/src/uplink/join.rs b/chirpstack/src/uplink/join.rs index be2ac819..1c5b6edd 100644 --- a/chirpstack/src/uplink/join.rs +++ b/chirpstack/src/uplink/join.rs @@ -218,7 +218,7 @@ impl JoinRequest { trace!("Filtering rx_info by tenant_id"); filter_rx_info_by_tenant_id( - &self.application.as_ref().unwrap().tenant_id, + self.application.as_ref().unwrap().tenant_id, &mut self.uplink_frame_set, )?; Ok(()) diff --git a/chirpstack/src/uplink/mod.rs b/chirpstack/src/uplink/mod.rs index 1d300cd7..40cac1cb 100644 --- a/chirpstack/src/uplink/mod.rs +++ b/chirpstack/src/uplink/mod.rs @@ -354,7 +354,7 @@ async fn update_gateway_metadata(ufs: &mut UplinkFrameSet) -> Result<()> { Ok(()) } -fn filter_rx_info_by_tenant_id(tenant_id: &Uuid, uplink: &mut UplinkFrameSet) -> Result<()> { +fn filter_rx_info_by_tenant_id(tenant_id: Uuid, uplink: &mut UplinkFrameSet) -> Result<()> { let mut rx_info_set: Vec = Vec::new(); for rx_info in &uplink.rx_info_set { @@ -366,15 +366,17 @@ fn filter_rx_info_by_tenant_id(tenant_id: &Uuid, uplink: &mut UplinkFrameSet) -> .ok_or_else(|| anyhow!("No region_config_id in rx_info metadata"))?; let force_gws_private = config::get_force_gws_private(®ion_config_id)?; - if !(*uplink + if !(uplink .gateway_private_up_map .get(&gateway_id) - .ok_or_else(|| anyhow!("gateway_id missing in gateway_private_up_map"))? + .cloned() + .unwrap_or_else(|| true) || force_gws_private) || uplink .gateway_tenant_id_map .get(&gateway_id) - .ok_or_else(|| anyhow!("gateway_id is missing in gateway_tenant_id_map"))? + .cloned() + .unwrap_or_else(|| Uuid::new_v4()) == tenant_id { rx_info_set.push(rx_info.clone()); @@ -383,7 +385,7 @@ fn filter_rx_info_by_tenant_id(tenant_id: &Uuid, uplink: &mut UplinkFrameSet) -> uplink.rx_info_set = rx_info_set; if uplink.rx_info_set.is_empty() { - return Err(anyhow!("rx_info_set has no items")); + return Err(anyhow!("RxInfo set is empty after applying filters")); } Ok(())