fix: Give better errors for read_to_string

This commit is contained in:
Gerald Pinder 2024-04-16 17:34:04 -04:00
parent 7c4c6759ca
commit 4ef0bf9169
3 changed files with 15 additions and 12 deletions

View file

@ -4,7 +4,7 @@ use std::{
process::Command,
};
use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use blue_build_recipe::Recipe;
use blue_build_utils::constants::{
ARCHIVE_SUFFIX, BUILD_ID_LABEL, CI_DEFAULT_BRANCH, CI_PROJECT_NAME, CI_PROJECT_NAMESPACE,
@ -133,14 +133,16 @@ impl BlueBuildCommand for BuildCommand {
let container_file_path = Path::new(CONTAINER_FILE);
if !self.force && container_file_path.exists() {
let gitignore = fs::read_to_string(GITIGNORE_PATH)?;
let gitignore = fs::read_to_string(GITIGNORE_PATH)
.context(format!("Failed to read {GITIGNORE_PATH}"))?;
let is_ignored = gitignore
.lines()
.any(|line: &str| line.contains(CONTAINER_FILE));
if !is_ignored {
let containerfile = fs::read_to_string(container_file_path)?;
let containerfile = fs::read_to_string(container_file_path)
.context(format!("Failed to read {}", container_file_path.display()))?;
let has_label = containerfile.lines().any(|line| {
let label = format!("LABEL {BUILD_ID_LABEL}");
line.to_string().trim().starts_with(&label)
@ -532,7 +534,8 @@ fn check_cosign_files() -> Result<()> {
}
let calculated_pub_key = String::from_utf8(output.stdout)?;
let found_pub_key = fs::read_to_string(COSIGN_PATH)?;
let found_pub_key =
fs::read_to_string(COSIGN_PATH).context(format!("Failed to read {COSIGN_PATH}"))?;
trace!("calculated_pub_key={calculated_pub_key},found_pub_key={found_pub_key}");
if calculated_pub_key.trim() == found_pub_key.trim() {