mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-29 23:57:51 +00:00
simple_op_store: add object type and id to protobuf decode errors
This commit is contained in:
parent
56750bb360
commit
55520a0e9c
1 changed files with 23 additions and 4 deletions
|
@ -21,6 +21,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use prost::Message;
|
||||
use tempfile::{NamedTempFile, PersistError};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::backend::{CommitId, MillisSinceEpoch, ObjectId, Timestamp};
|
||||
use crate::content_hash::blake2b_hash;
|
||||
|
@ -36,8 +37,17 @@ impl From<PersistError> for OpStoreError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<prost::DecodeError> for OpStoreError {
|
||||
fn from(err: prost::DecodeError) -> Self {
|
||||
#[derive(Debug, Error)]
|
||||
#[error("Failed to read {kind} with ID {id}: {err}")]
|
||||
struct DecodeError {
|
||||
kind: &'static str,
|
||||
id: String,
|
||||
#[source]
|
||||
err: prost::DecodeError,
|
||||
}
|
||||
|
||||
impl From<DecodeError> for OpStoreError {
|
||||
fn from(err: DecodeError) -> Self {
|
||||
OpStoreError::Other(err.into())
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +92,11 @@ impl OpStore for SimpleOpStore {
|
|||
let path = self.view_path(id);
|
||||
let buf = fs::read(path).map_err(|err| not_found_to_store_error(err, id))?;
|
||||
|
||||
let proto = crate::protos::op_store::View::decode(&*buf)?;
|
||||
let proto = crate::protos::op_store::View::decode(&*buf).map_err(|err| DecodeError {
|
||||
kind: "view",
|
||||
id: id.hex(),
|
||||
err,
|
||||
})?;
|
||||
Ok(view_from_proto(proto))
|
||||
}
|
||||
|
||||
|
@ -106,7 +120,12 @@ impl OpStore for SimpleOpStore {
|
|||
let path = self.operation_path(id);
|
||||
let buf = fs::read(path).map_err(|err| not_found_to_store_error(err, id))?;
|
||||
|
||||
let proto = crate::protos::op_store::Operation::decode(&*buf)?;
|
||||
let proto =
|
||||
crate::protos::op_store::Operation::decode(&*buf).map_err(|err| DecodeError {
|
||||
kind: "operation",
|
||||
id: id.hex(),
|
||||
err,
|
||||
})?;
|
||||
Ok(operation_from_proto(proto))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue