Skip to content

Commit

Permalink
refactor: Remove unwrap and handle errors (#213)
Browse files Browse the repository at this point in the history
* refactor: Remove unwrap and handle errors

Co-authored-by: Aviram Hassan <[email protected]>
Co-authored-by: Eyal Bukchin <[email protected]>
  • Loading branch information
3 people authored Aug 17, 2022
1 parent 10ca725 commit 6f64652
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Use Kubernetes beta feature `Ephemeral Containers` to mirror traffic with the `-
- E2E: Collect minikube logs and fix collecting container logs
- E2E: macOS use colima instead of minikube.
- Refactored `mirrord-layer/lib.rs` - no more passing many arguments! :)
- Refactored `mirrord-layer/lib.rs` - remove `unwrap()` and propagate error using `Result`

### Fixed
- Handle unwraps in fileops to gracefully exit and enable python fileops tests.
Expand Down
13 changes: 6 additions & 7 deletions mirrord-layer/src/pod_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ impl RuntimeData {
pod_name: &str,
pod_namespace: &str,
container_name: &Option<String>,
) -> Self {
) -> Result<Self> {
let pods_api: Api<Pod> = Api::namespaced(client, pod_namespace);
let pod = pods_api.get(pod_name).await.unwrap();
let pod = pods_api.get(pod_name).await?;
let node_name = &pod.spec.unwrap().node_name;
let container_statuses = &pod.status.unwrap().container_statuses.unwrap();
let container_info = if let Some(container_name) = container_name {
Expand All @@ -43,8 +43,7 @@ impl RuntimeData {
"no container named {} found in namespace={}, pod={}",
&container_name, &pod_namespace, &pod_name
)
})
.unwrap()
})?
.container_id
} else {
info!("No container name specified, defaulting to first container found");
Expand All @@ -65,12 +64,12 @@ impl RuntimeData {

let container_id = container_info.last().unwrap();

RuntimeData {
Ok(RuntimeData {
container_id: container_id.to_string(),
container_runtime: container_runtime.to_string(),
node_name: node_name.as_ref().unwrap().to_string(),
socket_path: socket_path.to_string(),
}
})
}
}

Expand Down Expand Up @@ -120,7 +119,7 @@ pub(crate) async fn create_agent(
&config,
agent_image,
&pods_api,
runtime_data,
runtime_data.unwrap(),
&jobs_api,
connection_port,
)
Expand Down

0 comments on commit 6f64652

Please sign in to comment.