Skip to content

Commit

Permalink
Create InvalidCheckpoint error to bucket errors relevant to checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevenannn committed Dec 12, 2024
1 parent 702e12f commit f288afe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions kernel/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions kernel/src/log_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl LogSegment {
{
require!(
checkpoint_file.version + 1 == commit_file.version,
Error::generic(format!(
Error::invalid_checkpoint(format!(
"Gap between checkpoint version {} and next commit {}",
checkpoint_file.version, commit_file.version,
))
Expand Down Expand Up @@ -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",
));
};
Expand All @@ -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::invalid_checkpoint(format!(
"_last_checkpoint indicated that checkpoint should have {} parts, but it has {}",
checkpoint_metadata.parts.unwrap_or(1),
checkpoint_parts.len()
Expand Down

0 comments on commit f288afe

Please sign in to comment.