@@ -6,7 +6,9 @@ use diesel::prelude::{
66} ;
77use graph:: {
88 data:: subgraph:: schema:: SubgraphError ,
9- prelude:: { bigdecimal:: ToPrimitive , BigDecimal , StoreError , SubgraphDeploymentId } ,
9+ prelude:: {
10+ bigdecimal:: ToPrimitive , BigDecimal , EthereumBlockPointer , StoreError , SubgraphDeploymentId ,
11+ } ,
1012} ;
1113use graph:: {
1214 data:: subgraph:: { schema:: SubgraphHealth , status} ,
@@ -139,9 +141,16 @@ impl TryFrom<ErrorDetail> for SubgraphError {
139141 deterministic,
140142 block_range,
141143 } = value;
142- let block_number = crate :: block_range:: first_block_in_range ( & block_range) . map ( |n| n. into ( ) ) ;
143- let block_ptr = block ( & subgraph_id, "fatal_error" , block_hash, block_number) ?
144- . map ( |block| block. to_ptr ( ) ) ;
144+ let block_number = crate :: block_range:: first_block_in_range ( & block_range) ;
145+ let block_hash = block_hash. map ( |hash| H256 :: from_slice ( hash. as_slice ( ) ) ) ;
146+ // In existing databases, we have errors that have a `block_range` of
147+ // `UNVERSIONED_RANGE`, which leads to `None` as the block number, but
148+ // has a hash. Conversely, it is also possible for an error to not have a
149+ // hash. In both cases, use a block pointer of `None`
150+ let block_ptr = match ( block_number, block_hash) {
151+ ( Some ( number) , Some ( hash) ) => EthereumBlockPointer :: from ( number as u64 , hash) ,
152+ _ => None ,
153+ } ;
145154 let subgraph_id = SubgraphDeploymentId :: new ( subgraph_id) . map_err ( |id| {
146155 StoreError :: ConstraintViolation ( format ! ( "invalid subgraph id `{}` in fatal error" , id) )
147156 } ) ?;
0 commit comments