fix(tvix/store) RedbPathInfoService: improve logs and errors
Add more logging and remove context from errors because that's already provided by the logs (Errors also need to be refactored anyway, there's also confusion about StorageError vs InvalidRequest, there's no consistency) Change-Id: Ia43c0d237d9075152490c635b05fb3fb343abcc8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12058 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
a794790203
commit
9cbebfea27
1 changed files with 10 additions and 6 deletions
|
@ -56,9 +56,9 @@ impl RedbPathInfoService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensures all tables are present.
|
/// Ensures all tables are present.
|
||||||
|
/// Opens a write transaction and calls open_table on PATHINFO_TABLE, which will
|
||||||
|
/// create it if not present.
|
||||||
fn create_schema(db: &redb::Database) -> Result<(), redb::Error> {
|
fn create_schema(db: &redb::Database) -> Result<(), redb::Error> {
|
||||||
// Opens a write transaction and calls open_table on PATHINFO_TABLE, which will
|
|
||||||
// create it if not present.
|
|
||||||
let txn = db.begin_write()?;
|
let txn = db.begin_write()?;
|
||||||
txn.open_table(PATHINFO_TABLE)?;
|
txn.open_table(PATHINFO_TABLE)?;
|
||||||
txn.commit()?;
|
txn.commit()?;
|
||||||
|
@ -80,7 +80,7 @@ impl PathInfoService for RedbPathInfoService {
|
||||||
Some(pathinfo_bytes) => Ok(Some(
|
Some(pathinfo_bytes) => Ok(Some(
|
||||||
PathInfo::decode(pathinfo_bytes.value().as_slice()).map_err(|e| {
|
PathInfo::decode(pathinfo_bytes.value().as_slice()).map_err(|e| {
|
||||||
warn!(err=%e, "failed to decode stored PathInfo");
|
warn!(err=%e, "failed to decode stored PathInfo");
|
||||||
Error::StorageError(format!("failed to decode stored PathInfo: {}", e))
|
Error::StorageError("failed to decode stored PathInfo".to_string())
|
||||||
})?,
|
})?,
|
||||||
)),
|
)),
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
|
@ -95,7 +95,10 @@ impl PathInfoService for RedbPathInfoService {
|
||||||
// Call validate on the received PathInfo message.
|
// Call validate on the received PathInfo message.
|
||||||
let store_path = path_info
|
let store_path = path_info
|
||||||
.validate()
|
.validate()
|
||||||
.map_err(|e| Error::InvalidRequest(format!("failed to validate PathInfo: {}", e)))?
|
.map_err(|e| {
|
||||||
|
warn!(err=%e, "failed to validate PathInfo");
|
||||||
|
Error::StorageError("failed to validate PathInfo".to_string())
|
||||||
|
})?
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
let path_info_encoded = path_info.encode_to_vec();
|
let path_info_encoded = path_info.encode_to_vec();
|
||||||
|
@ -110,7 +113,7 @@ impl PathInfoService for RedbPathInfoService {
|
||||||
.insert(store_path.digest(), path_info_encoded)
|
.insert(store_path.digest(), path_info_encoded)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!(err=%e, "failed to insert PathInfo");
|
warn!(err=%e, "failed to insert PathInfo");
|
||||||
Error::StorageError(format!("failed to insert PathInfo: {}", e))
|
Error::StorageError("failed to insert PathInfo".to_string())
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
Ok(txn.commit()?)
|
Ok(txn.commit()?)
|
||||||
|
@ -136,7 +139,8 @@ impl PathInfoService for RedbPathInfoService {
|
||||||
tokio::runtime::Handle::current()
|
tokio::runtime::Handle::current()
|
||||||
.block_on(tx.send(Ok(
|
.block_on(tx.send(Ok(
|
||||||
PathInfo::decode(elem.1.value().as_slice()).map_err(|e| {
|
PathInfo::decode(elem.1.value().as_slice()).map_err(|e| {
|
||||||
Error::InvalidRequest(format!("invalid PathInfo: {}", e))
|
warn!(err=%e, "invalid PathInfo");
|
||||||
|
Error::StorageError("invalid PathInfo".to_string())
|
||||||
})?,
|
})?,
|
||||||
)))
|
)))
|
||||||
.map_err(|e| Error::StorageError(e.to_string()))?;
|
.map_err(|e| Error::StorageError(e.to_string()))?;
|
||||||
|
|
Loading…
Reference in a new issue