Better context when erroring

This commit is contained in:
Kirill Bulatov
2021-10-05 10:16:08 +03:00
committed by Kirill Bulatov
parent 99dbbe5f18
commit abb2ac5246
2 changed files with 24 additions and 5 deletions

View File

@@ -268,9 +268,22 @@ pub(crate) fn get_branches(
// with timeline_id.
let branches_dir = conf.branches_path(tenantid);
std::fs::read_dir(&branches_dir)?
std::fs::read_dir(&branches_dir)
.with_context(|| {
format!(
"Found no branches directory '{}' for tenant {}",
branches_dir.display(),
tenantid
)
})?
.map(|dir_entry_res| {
let dir_entry = dir_entry_res?;
let dir_entry = dir_entry_res.with_context(|| {
format!(
"Failed to list branches directory '{}' content for tenant {}",
branches_dir.display(),
tenantid
)
})?;
BranchInfo::from_path(
dir_entry.path(),
conf,

View File

@@ -30,7 +30,7 @@ use crate::layered_repository::RELISH_SEG_SIZE;
use crate::virtual_file::VirtualFile;
use crate::PageServerConf;
use crate::{ZTenantId, ZTimelineId};
use anyhow::{anyhow, bail, ensure, Result};
use anyhow::{anyhow, bail, ensure, Context, Result};
use bytes::Bytes;
use log::*;
use serde::{Deserialize, Serialize};
@@ -386,8 +386,14 @@ impl ImageLayer {
}
let path = self.path();
let file = VirtualFile::open(&path)?;
let book = Book::new(file)?;
let file = VirtualFile::open(&path)
.with_context(|| format!("Failed to open virtual file '{}'", path.display()))?;
let book = Book::new(file).with_context(|| {
format!(
"Failed to open virtual file '{}' as a bookfile",
path.display()
)
})?;
match &self.path_or_conf {
PathOrConf::Conf(_) => {