Skip to content

Commit

Permalink
refactor: use anyhow context function
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenautumns committed Nov 4, 2024
1 parent 6c7f714 commit 8700e2a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::io::BufRead;
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};

use anyhow::{anyhow, bail, Ok};
use anyhow::{bail, Context, Ok};
use itertools::Itertools;
use nix::sys::statfs;
use nix::unistd::Pid;
Expand Down Expand Up @@ -278,7 +278,7 @@ pub fn mount_point() -> anyhow::Result<PathBuf> {
.mountinfo()?
.into_iter()
.find(|m| m.fs_type.eq("cgroup2")) // TODO A process can have several cgroup mounts
.ok_or_else(|| anyhow!("no cgroup2 mount found"))
.context("no cgroup2 mount found")
.map(|m| m.mount_point.clone())
}

Expand All @@ -289,7 +289,7 @@ pub fn current_cgroup() -> anyhow::Result<PathBuf> {
.cgroups()?
.into_iter()
.next()
.ok_or(anyhow!("cannot obtain cgroup"))?
.context("cannot obtain cgroup")?
.pathname
.clone();
let path = &path[1..path.len()]; // Remove the leading '/'
Expand Down
4 changes: 2 additions & 2 deletions core/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::PhantomData;
use std::mem::{size_of, MaybeUninit};
use std::os::unix::prelude::{AsRawFd, FileExt, IntoRawFd, RawFd};

use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};
use memfd::{FileSeal, Memfd, MemfdOptions};
use memmap2::{Mmap, MmapMut};
use nix::unistd::{close, dup};
Expand Down Expand Up @@ -183,6 +183,6 @@ pub fn get_memfd(name: &str) -> TypedResult<i32> {
None
}
})
.ok_or_else(|| anyhow!("No File Descriptor with Name: {name}"))
.with_context(|| format!("No File Descriptor with Name: {name}"))
.typ(SystemError::Panic)
}
4 changes: 2 additions & 2 deletions hypervisor/src/hypervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use a653rs_linux_core::error::{ErrorLevel, LeveledResult, ResultExt, SystemError
use a653rs_linux_core::file::TempFile;
use a653rs_linux_core::queuing::Queuing;
use a653rs_linux_core::sampling::Sampling;
use anyhow::anyhow;
use anyhow::{anyhow, Context};
use config::{Channel, Config};
use once_cell::sync::OnceCell;
use partition::Partition;
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Hypervisor {

let sys_time = SYSTEM_START_TIME
.get()
.ok_or_else(|| anyhow!("SystemTime was not set"))
.context("SystemTime was not set")
.lev_typ(SystemError::Panic, ErrorLevel::ModuleInit)?;
sys_time.write(&frame_start).lev(ErrorLevel::ModuleInit)?;
sys_time.seal_read_only().lev(ErrorLevel::ModuleInit)?;
Expand Down

0 comments on commit 8700e2a

Please sign in to comment.