Skip to content

Commit

Permalink
containerenv: small error message fix
Browse files Browse the repository at this point in the history
This tweaks the error message when `.containerenv` cannot be found so
that a fully-qualified path is included in the error.

Previously, the error message would just show `run/.containerenv` as
the path to the file, which is not entirely clear.

I tried to change the `const PATH` to be an absolute path, but doing
so breaks the ability for `open_optional()` to open the file
successfully; returns an error `a path led outside of the filesystem`.

Signed-off-by: Micah Abbott <[email protected]>
  • Loading branch information
miabbott committed Nov 11, 2023
1 parent 48325ba commit 641bb5a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/src/containerenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cap_std_ext::cap_std::fs::Dir;
use cap_std_ext::prelude::CapStdExtDirExt;
use fn_error_context::context;

/// Path is relative to container rootfs (assumed to be /)
const PATH: &str = "run/.containerenv";

#[derive(Debug, Default)]
Expand All @@ -25,7 +26,9 @@ pub(crate) fn get_container_execution_info(rootfs: &Dir) -> Result<ContainerExec
let f = match rootfs.open_optional(PATH)? {
Some(f) => BufReader::new(f),
None => {
anyhow::bail!("This command must be executed inside a podman container (missing {PATH}")
anyhow::bail!(
"This command must be executed inside a podman container (missing /{PATH})"
)
}
};
let mut r = ContainerExecutionInfo::default();
Expand Down

0 comments on commit 641bb5a

Please sign in to comment.