mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Removed weird ProviderError variants (#14518)
This commit is contained in:
@ -303,8 +303,7 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
|
||||
pub fn report_metrics(&self) -> ProviderResult<()> {
|
||||
let Some(metrics) = &self.metrics else { return Ok(()) };
|
||||
|
||||
let static_files =
|
||||
iter_static_files(&self.path).map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
let static_files = iter_static_files(&self.path).map_err(ProviderError::other)?;
|
||||
for (segment, ranges) in static_files {
|
||||
let mut entries = 0;
|
||||
let mut size = 0;
|
||||
@ -429,10 +428,10 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
|
||||
jar.jar
|
||||
} else {
|
||||
NippyJar::<SegmentHeader>::load(&self.path.join(segment.filename(&fixed_block_range)))
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?
|
||||
.map_err(ProviderError::other)?
|
||||
};
|
||||
|
||||
jar.delete().map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
jar.delete().map_err(ProviderError::other)?;
|
||||
|
||||
let mut segment_max_block = None;
|
||||
if fixed_block_range.start() > 0 {
|
||||
@ -461,7 +460,7 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
|
||||
} else {
|
||||
trace!(target: "provider::static_file", ?segment, ?fixed_block_range, "Creating jar from scratch");
|
||||
let path = self.path.join(segment.filename(fixed_block_range));
|
||||
let jar = NippyJar::load(&path).map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
let jar = NippyJar::load(&path).map_err(ProviderError::other)?;
|
||||
self.map.entry(key).insert(LoadedJar::new(jar)?).downgrade().into()
|
||||
};
|
||||
|
||||
@ -535,7 +534,7 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
|
||||
let jar = NippyJar::<SegmentHeader>::load(
|
||||
&self.path.join(segment.filename(&fixed_range)),
|
||||
)
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
.map_err(ProviderError::other)?;
|
||||
|
||||
// Updates the tx index by first removing all entries which have a higher
|
||||
// block_start than our current static file.
|
||||
@ -600,9 +599,7 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
|
||||
max_block.clear();
|
||||
tx_index.clear();
|
||||
|
||||
for (segment, ranges) in
|
||||
iter_static_files(&self.path).map_err(|e| ProviderError::NippyJar(e.to_string()))?
|
||||
{
|
||||
for (segment, ranges) in iter_static_files(&self.path).map_err(ProviderError::other)? {
|
||||
// Update last block for each segment
|
||||
if let Some((block_range, _)) = ranges.last() {
|
||||
max_block.insert(segment, block_range.end());
|
||||
@ -819,12 +816,9 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
|
||||
let file_path =
|
||||
self.directory().join(segment.filename(&self.find_fixed_range(latest_block)));
|
||||
|
||||
let jar = NippyJar::<SegmentHeader>::load(&file_path)
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
let jar = NippyJar::<SegmentHeader>::load(&file_path).map_err(ProviderError::other)?;
|
||||
|
||||
NippyJarChecker::new(jar)
|
||||
.check_consistency()
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
NippyJarChecker::new(jar).check_consistency().map_err(ProviderError::other)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ impl LoadedJar {
|
||||
let mmap_handle = Arc::new(data_reader);
|
||||
Ok(Self { jar, mmap_handle })
|
||||
}
|
||||
Err(e) => Err(ProviderError::NippyJar(e.to_string())),
|
||||
Err(e) => Err(ProviderError::other(e)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ use reth_primitives::{
|
||||
static_file::{SegmentHeader, SegmentRangeInclusive},
|
||||
StaticFileSegment,
|
||||
};
|
||||
use reth_storage_errors::provider::{ProviderError, ProviderResult};
|
||||
use reth_storage_errors::provider::{ProviderError, ProviderResult, StaticFileWriterError};
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
fmt::Debug,
|
||||
@ -163,8 +163,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
None,
|
||||
) {
|
||||
Ok(provider) => (
|
||||
NippyJar::load(provider.data_path())
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?,
|
||||
NippyJar::load(provider.data_path()).map_err(ProviderError::other)?,
|
||||
provider.data_path().into(),
|
||||
),
|
||||
Err(ProviderError::MissingStaticFileBlock(_, _)) => {
|
||||
@ -180,7 +179,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
// This static file has been frozen, so we should
|
||||
Err(ProviderError::FinalizedStaticFile(segment, block))
|
||||
}
|
||||
Err(e) => Err(ProviderError::NippyJar(e.to_string())),
|
||||
Err(e) => Err(ProviderError::other(e)),
|
||||
}?;
|
||||
|
||||
if let Some(metrics) = &metrics {
|
||||
@ -214,7 +213,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
self.user_header_mut().prune(pruned_rows);
|
||||
}
|
||||
|
||||
self.writer.commit().map_err(|error| ProviderError::NippyJar(error.to_string()))?;
|
||||
self.writer.commit().map_err(ProviderError::other)?;
|
||||
|
||||
// Updates the [SnapshotProvider] manager
|
||||
self.update_index()?;
|
||||
@ -240,7 +239,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
|
||||
if self.writer.is_dirty() {
|
||||
// Commits offsets and new user_header to disk
|
||||
self.writer.commit().map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
self.writer.commit().map_err(ProviderError::other)?;
|
||||
|
||||
if let Some(metrics) = &self.metrics {
|
||||
metrics.record_segment_operation(
|
||||
@ -272,9 +271,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
let start = Instant::now();
|
||||
|
||||
// Commits offsets and new user_header to disk
|
||||
self.writer
|
||||
.commit_without_sync_all()
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
self.writer.commit_without_sync_all().map_err(ProviderError::other)?;
|
||||
|
||||
if let Some(metrics) = &self.metrics {
|
||||
metrics.record_segment_operation(
|
||||
@ -421,9 +418,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
} else {
|
||||
// Update `SegmentHeader`
|
||||
self.writer.user_header_mut().prune(len);
|
||||
self.writer
|
||||
.prune_rows(len as usize)
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
self.writer.prune_rows(len as usize).map_err(ProviderError::other)?;
|
||||
break
|
||||
}
|
||||
|
||||
@ -433,9 +428,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
self.writer.user_header_mut().prune(remaining_rows);
|
||||
|
||||
// Truncate data
|
||||
self.writer
|
||||
.prune_rows(remaining_rows as usize)
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
self.writer.prune_rows(remaining_rows as usize).map_err(ProviderError::other)?;
|
||||
remaining_rows = 0;
|
||||
}
|
||||
}
|
||||
@ -476,9 +469,9 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
self.writer.set_dirty();
|
||||
self.data_path = data_path;
|
||||
NippyJar::<SegmentHeader>::load(¤t_path)
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?
|
||||
.map_err(ProviderError::other)?
|
||||
.delete()
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
.map_err(ProviderError::other)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -487,9 +480,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
self.buf.clear();
|
||||
column.to_compact(&mut self.buf);
|
||||
|
||||
self.writer
|
||||
.append_column(Some(Ok(&self.buf)))
|
||||
.map_err(|e| ProviderError::NippyJar(e.to_string()))?;
|
||||
self.writer.append_column(Some(Ok(&self.buf))).map_err(ProviderError::other)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -762,9 +753,9 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
|
||||
/// Returns Error if there is a pruning instruction that needs to be applied.
|
||||
fn ensure_no_queued_prune(&self) -> ProviderResult<()> {
|
||||
if self.prune_on_commit.is_some() {
|
||||
return Err(ProviderError::NippyJar(
|
||||
"Pruning should be committed before appending or pruning more data".to_string(),
|
||||
))
|
||||
return Err(ProviderError::other(StaticFileWriterError::new(
|
||||
"Pruning should be committed before appending or pruning more data",
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user