Replace string comparison with pattern matching for error handling

Co-Authored-By: christian@neon.tech <christian@neon.tech>
This commit is contained in:
Devin AI
2025-05-06 19:28:51 +00:00
parent 486d9f0c4d
commit e32aceff16
2 changed files with 10 additions and 20 deletions

View File

@@ -615,9 +615,10 @@ impl DeltaLayerWriterInner {
let (_buf, res) = file.write_all_at(buf.slice_len(), 0, ctx).await;
res.map_err(|e| DeltaLayerWriterError::Other(anyhow::Error::new(e)))?;
let metadata = file.metadata().await.map_err(|e| {
DeltaLayerWriterError::Other(anyhow::Error::new(e))
})?;
let metadata = file
.metadata()
.await
.map_err(|e| DeltaLayerWriterError::Other(anyhow::Error::new(e)))?;
// 5GB limit for objects without multipart upload (which we don't want to use)
// Make it a little bit below to account for differing GB units
@@ -629,7 +630,6 @@ impl DeltaLayerWriterInner {
metadata.len()
)));
}
// Note: Because we opened the file in write-only mode, we cannot
// reuse the same VirtualFile for reading later. That's why we don't
@@ -646,7 +646,7 @@ impl DeltaLayerWriterInner {
// fsync the file
file.sync_all()
.await
.maybe_fatal_err("delta_layer sync_all")?;
.map_err(|e| DeltaLayerWriterError::Other(anyhow::Error::new(e)))?;
trace!("created delta layer {}", self.path);

View File

@@ -1575,9 +1575,7 @@ impl Timeline {
if keys_written > 0 {
let (desc, path) = image_layer_writer.finish(ctx).await.map_err(|e| match e {
ImageLayerWriterError::Cancelled => {
CompactionError::Other(anyhow::anyhow!("flush task cancelled"))
}
ImageLayerWriterError::Cancelled => CompactionError::Cancelled,
ImageLayerWriterError::Other(err) => CompactionError::Other(err),
})?;
let new_layer = Layer::finish_creating(self.conf, self, desc, &path)
@@ -2148,9 +2146,7 @@ impl Timeline {
.finish(prev_key.unwrap().next(), ctx)
.await
.map_err(|e| match e {
DeltaLayerWriterError::Cancelled => {
CompactionError::Other(anyhow::anyhow!("flush task cancelled"))
}
DeltaLayerWriterError::Cancelled => CompactionError::Cancelled,
DeltaLayerWriterError::Other(err) => CompactionError::Other(err),
})?;
let new_delta = Layer::finish_creating(self.conf, self, desc, &path)
@@ -2212,9 +2208,7 @@ impl Timeline {
.put_value(key, lsn, value, ctx)
.await
.map_err(|e| match e {
DeltaLayerWriterError::Cancelled => {
CompactionError::Other(anyhow::anyhow!("flush task cancelled"))
}
DeltaLayerWriterError::Cancelled => CompactionError::Cancelled,
DeltaLayerWriterError::Other(err) => CompactionError::Other(err),
})?;
} else {
@@ -3703,9 +3697,7 @@ impl Timeline {
.finish(job_desc.compaction_key_range.start, ctx)
.await
.map_err(|e| match e {
DeltaLayerWriterError::Cancelled => {
CompactionError::Other(anyhow::anyhow!("flush task cancelled"))
}
DeltaLayerWriterError::Cancelled => CompactionError::Cancelled,
DeltaLayerWriterError::Other(err) => CompactionError::Other(err),
})?;
let layer = Layer::finish_creating(self.conf, self, desc, &path)
@@ -3718,9 +3710,7 @@ impl Timeline {
.finish(key.key_range.end, ctx)
.await
.map_err(|e| match e {
DeltaLayerWriterError::Cancelled => {
CompactionError::Other(anyhow::anyhow!("flush task cancelled"))
}
DeltaLayerWriterError::Cancelled => CompactionError::Cancelled,
DeltaLayerWriterError::Other(err) => CompactionError::Other(err),
})?;
let layer = Layer::finish_creating(self.conf, self, desc, &path)