mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-17 15:38:00 +00:00
agent/rustjail: don't use unwrap in container::oci_state
replace unwrap with `match` statements, this way we can write unit tests that don't panic Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
5d111071be
commit
8130d9b2dd
@ -698,7 +698,11 @@ impl BaseContainer for LinuxContainer {
|
||||
}
|
||||
|
||||
fn oci_state(&self) -> Result<OCIState> {
|
||||
let oci = self.config.spec.as_ref().unwrap();
|
||||
let oci = match self.config.spec.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(anyhow!("Unable to get OCI state: spec not found")),
|
||||
};
|
||||
|
||||
let status = self.status();
|
||||
let pid = if status != Status::STOPPED {
|
||||
self.init_process_pid
|
||||
@ -706,9 +710,17 @@ impl BaseContainer for LinuxContainer {
|
||||
0
|
||||
};
|
||||
|
||||
let root = oci.root.as_ref().unwrap().path.as_str();
|
||||
let root = match oci.root.as_ref() {
|
||||
Some(s) => s.path.as_str(),
|
||||
None => return Err(anyhow!("Unable to get root path: oci.root is none")),
|
||||
};
|
||||
|
||||
let path = fs::canonicalize(root)?;
|
||||
let bundle = path.parent().unwrap().to_str().unwrap().to_string();
|
||||
let bundle = match path.parent() {
|
||||
Some(s) => s.to_str().unwrap().to_string(),
|
||||
None => return Err(anyhow!("could not get root parent: root path {:?}", path)),
|
||||
};
|
||||
|
||||
Ok(OCIState {
|
||||
version: oci.version.clone(),
|
||||
id: self.id(),
|
||||
|
Loading…
Reference in New Issue
Block a user