fix(bug): replace unwrap() with unwrap_or_default() to propagate errors for better handling

This commit is contained in:
scutKKsix 2025-04-22 17:36:50 +08:00 committed by Samuel Dai
parent 2f83a94476
commit 9277d3ef0b
2 changed files with 3 additions and 3 deletions

View File

@ -28,7 +28,7 @@ pub async fn get_function(function_name: &str, namespace: &str) -> Result<Functi
let container = ContainerdManager::load_container(cid, namespace) let container = ContainerdManager::load_container(cid, namespace)
.await .await
.map_err(|e| FunctionError::FunctionNotFound(e.to_string()))? .map_err(|e| FunctionError::FunctionNotFound(e.to_string()))?
.unwrap(); .unwrap_or_default();
let container_name = container.id.to_string(); let container_name = container.id.to_string();
let image = container.image.clone(); let image = container.image.clone();

View File

@ -492,8 +492,8 @@ impl ContainerdManager {
pub fn get_address(cid: &str) -> String { pub fn get_address(cid: &str) -> String {
let map = GLOBAL_NETNS_MAP.read().unwrap(); let map = GLOBAL_NETNS_MAP.read().unwrap();
let config = map.get(cid).unwrap(); let addr = map.get(cid).map(|net_conf| net_conf.get_address());
config.get_address() addr.unwrap_or_default()
} }
fn remove_container_network_config(cid: &str) { fn remove_container_network_config(cid: &str) {