diff --git a/ffi/src/error.rs b/ffi/src/error.rs index 629cac619..a615d0330 100644 --- a/ffi/src/error.rs +++ b/ffi/src/error.rs @@ -51,6 +51,7 @@ pub enum KernelError { ParseIntervalError, ChangeDataFeedUnsupported, ChangeDataFeedIncompatibleSchema, + InvalidCheckpoint, } impl From for KernelError { @@ -108,6 +109,7 @@ impl From for KernelError { Error::ChangeDataFeedIncompatibleSchema(_, _) => { KernelError::ChangeDataFeedIncompatibleSchema } + Error::InvalidCheckpoint(_) => KernelError::InvalidCheckpoint, } } } diff --git a/kernel/src/error.rs b/kernel/src/error.rs index 7fb6e5d60..d3e5e53c9 100644 --- a/kernel/src/error.rs +++ b/kernel/src/error.rs @@ -191,6 +191,10 @@ pub enum Error { #[error("Change data feed encountered incompatible schema. Expected {0}, got {1}")] ChangeDataFeedIncompatibleSchema(String, String), + + /// Invalid checkpoint files + #[error("Invalid Checkpoint: {0}")] + InvalidCheckpoint(String), } // Convenience constructors for Error types that take a String argument @@ -264,6 +268,10 @@ impl Error { Self::ChangeDataFeedIncompatibleSchema(format!("{expected:?}"), format!("{actual:?}")) } + pub fn invalid_checkpoint(msg: impl ToString) -> Self { + Self::InvalidCheckpoint(msg.to_string()) + } + // Capture a backtrace when the error is constructed. #[must_use] pub fn with_backtrace(self) -> Self { diff --git a/kernel/src/log_segment.rs b/kernel/src/log_segment.rs index c7567a087..24d78a986 100644 --- a/kernel/src/log_segment.rs +++ b/kernel/src/log_segment.rs @@ -68,7 +68,7 @@ impl LogSegment { { require!( checkpoint_file.version + 1 == commit_file.version, - Error::generic(format!( + Error::InvalidCheckpoint(format!( "Gap between checkpoint version {} and next commit {}", checkpoint_file.version, commit_file.version, )) @@ -358,7 +358,7 @@ fn list_log_files_with_checkpoint( let Some(latest_checkpoint) = checkpoint_parts.last() else { // TODO: We could potentially recover here - return Err(Error::generic( + return Err(Error::invalid_checkpoint( "Had a _last_checkpoint hint but didn't find any checkpoints", )); }; @@ -369,7 +369,7 @@ fn list_log_files_with_checkpoint( latest_checkpoint.version ); } else if checkpoint_parts.len() != checkpoint_metadata.parts.unwrap_or(1) { - return Err(Error::Generic(format!( + return Err(Error::InvalidCheckpoint(format!( "_last_checkpoint indicated that checkpoint should have {} parts, but it has {}", checkpoint_metadata.parts.unwrap_or(1), checkpoint_parts.len()