agent: Wrap remaining nix errors with anyhow

Wrap `nix` `Error`'s in an `anyhow` error for consistency with the way
`rustjail` handles errors.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt 2021-11-30 13:26:15 +00:00
parent aba572e01d
commit afb96c0044
2 changed files with 4 additions and 4 deletions

View File

@ -523,7 +523,7 @@ impl Handle {
.as_ref() .as_ref()
.map(|to| to.address.as_str()) // Extract address field .map(|to| to.address.as_str()) // Extract address field
.and_then(|addr| if addr.is_empty() { None } else { Some(addr) }) // Make sure it's not empty .and_then(|addr| if addr.is_empty() { None } else { Some(addr) }) // Make sure it's not empty
.ok_or(nix::Error::EINVAL)?; .ok_or(anyhow!(nix::Error::EINVAL))?;
let ip = IpAddr::from_str(ip_address) let ip = IpAddr::from_str(ip_address)
.map_err(|e| anyhow!("Failed to parse IP {}: {:?}", ip_address, e))?; .map_err(|e| anyhow!("Failed to parse IP {}: {:?}", ip_address, e))?;
@ -612,7 +612,7 @@ fn parse_mac_address(addr: &str) -> Result<[u8; 6]> {
// Parse single Mac address block // Parse single Mac address block
let mut parse_next = || -> Result<u8> { let mut parse_next = || -> Result<u8> {
let v = u8::from_str_radix(split.next().ok_or(nix::Error::EINVAL)?, 16)?; let v = u8::from_str_radix(split.next().ok_or(anyhow!(nix::Error::EINVAL))?, 16)?;
Ok(v) Ok(v)
}; };

View File

@ -1526,7 +1526,7 @@ fn do_copy_file(req: &CopyFileRequest) -> Result<()> {
let path = PathBuf::from(req.path.as_str()); let path = PathBuf::from(req.path.as_str());
if !path.starts_with(CONTAINER_BASE) { if !path.starts_with(CONTAINER_BASE) {
return Err(nix::Error::EINVAL.into()); return Err(anyhow!(nix::Error::EINVAL));
} }
let parent = path.parent(); let parent = path.parent();
@ -1606,7 +1606,7 @@ fn setup_bundle(cid: &str, spec: &mut Spec) -> Result<PathBuf> {
let spec_root = if let Some(sr) = &spec.root { let spec_root = if let Some(sr) = &spec.root {
sr sr
} else { } else {
return Err(nix::Error::EINVAL.into()); return Err(anyhow!(nix::Error::EINVAL));
}; };
let spec_root_path = Path::new(&spec_root.path); let spec_root_path = Path::new(&spec_root.path);