Skip to content

Commit 33ae592

Browse files
committed
store: Provide more detail in errors from private data source copy
1 parent 1129ee0 commit 33ae592

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

store/postgres/src/dynds/private.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, ops::Bound};
1+
use std::{collections::HashMap, i32, ops::Bound};
22

33
use diesel::{
44
pg::{sql_types, Pg},
@@ -249,7 +249,7 @@ impl DataSourcesTable {
249249
.order_by(&self.vid)
250250
.load::<DsForCopy>(conn)?
251251
.into_iter()
252-
.map(|ds| ds.src_to_dst(target_block, &manifest_map))
252+
.map(|ds| ds.src_to_dst(target_block, &manifest_map, &self.namespace, &dst.namespace))
253253
.collect::<Result<_, _>>()?;
254254

255255
// Split all dss into chunks so that we never use more than
@@ -348,14 +348,23 @@ impl ManifestIdxMap {
348348
ManifestIdxMap { map }
349349
}
350350

351-
fn dst_idx(&self, src_idx: i32) -> Result<i32, StoreError> {
351+
fn dst_idx(
352+
&self,
353+
src_idx: i32,
354+
src_nsp: &Namespace,
355+
src_created: BlockNumber,
356+
dst_nsp: &Namespace,
357+
) -> Result<i32, StoreError> {
352358
let (dst_idx, name) = self.map.get(&src_idx).with_context(|| {
353-
anyhow!("the source does not have a template with index {}", src_idx)
359+
anyhow!(
360+
"the source {src_nsp} does not have a template with \
361+
index {src_idx} but created one at block {src_created}"
362+
)
354363
})?;
355364
let dst_idx = dst_idx.with_context(|| {
356365
anyhow!(
357-
"the destination does not have a template with name {}",
358-
name
366+
"the destination {dst_nsp} is missing a template with \
367+
name {name}. The source {src_nsp} created one at block {src_created}"
359368
)
360369
})?;
361370
Ok(dst_idx)
@@ -377,14 +386,21 @@ impl DsForCopy {
377386
mut self,
378387
target_block: BlockNumber,
379388
map: &ManifestIdxMap,
389+
src_nsp: &Namespace,
390+
dst_nsp: &Namespace,
380391
) -> Result<Self, StoreError> {
381392
// unclamp block range if it ends beyond target block
382393
match self.block_range.1 {
383394
Bound::Included(block) if block > target_block => self.block_range.1 = Bound::Unbounded,
384395
_ => { /* use block range as is */ }
385396
}
386397
// Translate manifest index
387-
self.idx = map.dst_idx(self.idx)?;
398+
let src_created = match self.block_range.0 {
399+
Bound::Included(block) => block,
400+
Bound::Excluded(block) => block + 1,
401+
Bound::Unbounded => i32::MAX,
402+
};
403+
self.idx = map.dst_idx(self.idx, src_nsp, src_created, dst_nsp)?;
388404
Ok(self)
389405
}
390406
}

0 commit comments

Comments
 (0)