Skip to content

Commit

Permalink
Remove some unwrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Apr 23, 2024
1 parent 2276a4e commit f63b211
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 68 deletions.
4 changes: 2 additions & 2 deletions backend/basic/src/rbum/helper/rbum_event_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ pub async fn get_notify_event_with_ctx(ctx: &TardisContext) -> TardisResult<Opti
let notify_events = notify_events
.iter()
.filter(|(k, _)| k.starts_with(NOTIFY_EVENT_IN_CTX_FLAG))
.map(|(_, v)| TardisFuns::json.str_to_obj::<NotifyEventMessage>(v).unwrap())
.collect::<Vec<_>>();
.map(|(_, v)| TardisFuns::json.str_to_obj::<NotifyEventMessage>(v))
.collect::<TardisResult<Vec<_>>>()?;
if notify_events.is_empty() {
Ok(None)
} else {
Expand Down
2 changes: 1 addition & 1 deletion backend/basic/src/rbum/serv/rbum_cert_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
Query::select()
.column(rbum_cert::Column::Id)
.from(rbum_cert::Entity)
.and_where(Expr::col(rbum_cert::Column::Ak).eq(modify_req.ak.as_ref().unwrap().as_str()))
.and_where(Expr::col(rbum_cert::Column::Ak).eq(modify_req.ak.as_ref().expect("ignore").as_str()))
.and_where(Expr::col(rbum_cert::Column::RelRbumCertConfId).eq(rbum_cert_conf.id.clone()))
.and_where(Expr::col(rbum_cert::Column::OwnPaths).like(format!("{}%", ctx.own_paths).as_str()))
.and_where(Expr::col(rbum_cert::Column::Id).ne(id.to_string().as_str())),
Expand Down
14 changes: 7 additions & 7 deletions backend/basic/src/rbum/serv/rbum_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ where
}
if let Some(rel_item_ids) = &rbum_item_rel_filter_req.rel_item_ids {
if rel_item_ids.len() == 1 {
sub_query.and_where(Expr::col((rbum_rel::Entity, rbum_rel::Column::ToRbumItemId)).eq(rel_item_ids.first().unwrap().to_string()));
sub_query.and_where(Expr::col((rbum_rel::Entity, rbum_rel::Column::ToRbumItemId)).eq(rel_item_ids.first().expect("ignore").to_string()));
} else if !rel_item_ids.is_empty() {
sub_query.and_where(Expr::col((rbum_rel::Entity, rbum_rel::Column::ToRbumItemId)).is_in(rel_item_ids));
}
Expand Down Expand Up @@ -564,7 +564,7 @@ where
}
if let Some(rel_item_ids) = &rbum_item_rel_filter_req.rel_item_ids {
if rel_item_ids.len() == 1 {
sub_query.and_where(Expr::col((rbum_rel::Entity, rbum_rel::Column::FromRbumId)).eq(rel_item_ids.first().unwrap().to_string()));
sub_query.and_where(Expr::col((rbum_rel::Entity, rbum_rel::Column::FromRbumId)).eq(rel_item_ids.first().expect("ignore").to_string()));
} else if !rel_item_ids.is_empty() {
sub_query.and_where(Expr::col((rbum_rel::Entity, rbum_rel::Column::FromRbumId)).is_in(rel_item_ids));
}
Expand Down Expand Up @@ -1168,8 +1168,7 @@ impl RbumItemAttrServ {

for in_main_table_attr in in_main_table_attrs {
let column_name = Alias::new(&in_main_table_attr.name);
// TODO unwrap()
let column_val = add_req.values.get(&in_main_table_attr.name).unwrap().clone();
let column_val = add_req.values.get(&in_main_table_attr.name).expect("ignore").clone();
update_statement.value(column_name, Value::from(column_val));
}
update_statement.and_where(Expr::col(ID_FIELD.clone()).eq(add_req.rel_rbum_item_id.as_str()));
Expand All @@ -1178,7 +1177,7 @@ impl RbumItemAttrServ {

if !in_ext_table_attrs.is_empty() {
for in_ext_table_attr in in_ext_table_attrs {
let column_val = add_req.values.get(&in_ext_table_attr.name).unwrap().clone();
let column_val = add_req.values.get(&in_ext_table_attr.name).expect("ignore").clone();
let exist_item_attr_ids = Self::find_id_rbums(
&RbumItemAttrFilterReq {
basic: Default::default(),
Expand All @@ -1203,7 +1202,7 @@ impl RbumItemAttrServ {
)
.await?;
} else {
Self::modify_rbum(exist_item_attr_ids.get(0).unwrap(), &mut RbumItemAttrModifyReq { value: column_val }, funs, ctx).await?;
Self::modify_rbum(exist_item_attr_ids.get(0).expect("ignore"), &mut RbumItemAttrModifyReq { value: column_val }, funs, ctx).await?;
}
}
}
Expand All @@ -1222,6 +1221,7 @@ impl RbumItemAttrServ {
ctx,
)
.await?;
// TODO check logic
let result = if in_secret_table_attr.dyn_default_value.is_empty() {
if RbumKindAttrServ::url_match(&in_secret_table_attr.dyn_default_value).unwrap() {
let url = RbumKindAttrServ::url_replace(&in_secret_table_attr.dyn_default_value, add_req.values.clone()).unwrap();
Expand Down Expand Up @@ -1252,7 +1252,7 @@ impl RbumItemAttrServ {
)
.await?;
} else {
Self::modify_rbum(secret_item_attr_ids.get(0).unwrap(), &mut RbumItemAttrModifyReq { value: result }, funs, ctx).await?;
Self::modify_rbum(secret_item_attr_ids.get(0).expect("ignore"), &mut RbumItemAttrModifyReq { value: result }, funs, ctx).await?;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion backend/basic/src/rbum/serv/rbum_set_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl RbumSetServ {
tree_main
.iter()
.filter(|c| c.sys_code.starts_with(&cate.sys_code))
.flat_map(|c| items.get(&c.id).unwrap())
.flat_map(|c| items.get(&c.id).expect("ignore"))
.group_by(|c| c.rel_rbum_item_kind_id.clone())
.into_iter()
.map(|(g, c)| (g, c.map(|i| i.rel_rbum_item_id.clone()).collect::<HashSet<String>>().len() as u64))
Expand Down Expand Up @@ -377,6 +377,7 @@ impl RbumSetServ {
.filter(|cate| cate.pid == Some(cate_id.to_string()))
.flat_map(|cate| Self::filter_exist_items(tree_main, &cate.id, rbum_set_items))
.collect::<Vec<String>>();
// TODO remove unwrap
let cate = tree_main.iter().find(|cate| cate.id == cate_id).unwrap();
if sub_cates.is_empty() {
// leaf node
Expand Down
4 changes: 2 additions & 2 deletions backend/basic/src/spi/spi_funs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ impl SpiBsInst {
where
T: 'static,
{
let c = self.client.as_ref().downcast_ref::<T>().unwrap();
let c = self.client.as_ref().downcast_ref::<T>().expect("ignore");
(c, &self.ext, self.kind_code())
}

pub fn kind_code(&self) -> &str {
self.ext.get(spi_constants::SPI_KIND_CODE_FLAG).unwrap()
self.ext.get(spi_constants::SPI_KIND_CODE_FLAG).expect("ignore")
}
}

Expand Down
8 changes: 4 additions & 4 deletions backend/basic/src/spi/spi_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ pub mod common_pg {
let compatible_type = TardisFuns::json.json_to_obj(ext.get("compatible_type").unwrap_or(&tardis::serde_json::Value::String("None".to_string())).clone())?;
let client = TardisRelDBClient::init(&DBModuleConfig {
url: bs_cert.conn_uri.parse().expect("invalid url"),
max_connections: ext.get("max_connections").unwrap().as_u64().unwrap() as u32,
min_connections: ext.get("min_connections").unwrap().as_u64().unwrap() as u32,
max_connections: ext.get("max_connections").map(|c| c.as_u64()).flatten().unwrap_or(5) as u32,
min_connections: ext.get("min_connections").map(|c| c.as_u64()).flatten().unwrap_or(1) as u32,
connect_timeout_sec: None,
idle_timeout_sec: None,
compatible_type,
Expand Down Expand Up @@ -289,7 +289,7 @@ pub mod common_pg {
) -> TardisResult<(TardisRelDBlConnection, String)> {
let tag = tag.map(|t| format!("_{t}")).unwrap_or_default();
let conn = bs_inst.0.conn();
let schema_name = get_schema_name_from_ext(bs_inst.1).unwrap();
let schema_name = get_schema_name_from_ext(bs_inst.1).expect("ignore");
if check_table_exit(&format!("{table_flag}{tag}"), &conn, ctx).await? {
return Ok((conn, format!("{schema_name}.{GLOBAL_STORAGE_FLAG}_{table_flag}{tag}")));
} else if !mgr {
Expand All @@ -303,7 +303,7 @@ pub mod common_pg {
/// 初始化连接
pub async fn init_conn(bs_inst: TypedSpiBsInst<'_, TardisRelDBClient>) -> TardisResult<(TardisRelDBlConnection, String)> {
let conn = bs_inst.0.conn();
let schema_name = get_schema_name_from_ext(bs_inst.1).unwrap();
let schema_name = get_schema_name_from_ext(bs_inst.1).expect("ignore");
Ok((conn, schema_name))
}

Expand Down
51 changes: 0 additions & 51 deletions backend/gateways/test/src/init_apisix.rs

This file was deleted.

0 comments on commit f63b211

Please sign in to comment.