1- use anyhow:: anyhow;
21use bimap:: BiBTreeMap ;
32use cid:: Cid ;
43use fvm_ipld_blockstore:: Blockstore ;
5- use fvm_ipld_encoding:: CborStore ;
4+ use fvm_ipld_encoding:: { CborStore , CborStoreError } ;
65use num_derive:: FromPrimitive ;
76use serde_repr:: { Deserialize_repr , Serialize_repr } ;
87
@@ -107,26 +106,36 @@ impl From<&Type> for String {
107106/// A mapping of builtin actor CIDs to their respective types.
108107pub type Manifest = BiBTreeMap < Cid , Type > ;
109108
110- pub fn load_manifest < B : Blockstore > ( bs : & B , root_cid : & Cid , ver : u32 ) -> anyhow:: Result < Manifest > {
109+ pub fn load_manifest < B : Blockstore > (
110+ bs : & B ,
111+ root_cid : & Cid ,
112+ ver : u32 ,
113+ ) -> Result < Manifest , ManifestError < B > > {
111114 match ver {
112115 0 => load_manifest_v0 ( bs, root_cid) ,
113116 1 => load_manifest_v1 ( bs, root_cid) ,
114- _ => Err ( anyhow ! ( "unknown manifest version {}" , ver) ) ,
117+ _ => Err ( ManifestError :: UnknownVersion ( ver) ) ,
115118 }
116119}
117120
118- pub fn load_manifest_v0 < B : Blockstore > ( bs : & B , root_cid : & Cid ) -> anyhow:: Result < Manifest > {
121+ pub fn load_manifest_v0 < B : Blockstore > (
122+ bs : & B ,
123+ root_cid : & Cid ,
124+ ) -> Result < Manifest , ManifestError < B > > {
119125 match bs. get_cbor :: < Manifest > ( root_cid) ? {
120126 Some ( mf) => Ok ( mf) ,
121- None => Err ( anyhow ! ( "cannot find manifest root cid {}" , root_cid) ) ,
127+ None => Err ( ManifestError :: MissingRootCid ( * root_cid) ) ,
122128 }
123129}
124130
125- pub fn load_manifest_v1 < B : Blockstore > ( bs : & B , root_cid : & Cid ) -> anyhow:: Result < Manifest > {
131+ pub fn load_manifest_v1 < B : Blockstore > (
132+ bs : & B ,
133+ root_cid : & Cid ,
134+ ) -> Result < Manifest , ManifestError < B > > {
126135 let vec: Vec < ( String , Cid ) > = match bs. get_cbor ( root_cid) ? {
127136 Some ( vec) => vec,
128137 None => {
129- return Err ( anyhow ! ( "cannot find manifest root cid {}" , root_cid) ) ;
138+ return Err ( ManifestError :: MissingRootCid ( * root_cid) ) ;
130139 }
131140 } ;
132141 let mut manifest = Manifest :: new ( ) ;
@@ -137,9 +146,21 @@ pub fn load_manifest_v1<B: Blockstore>(bs: &B, root_cid: &Cid) -> anyhow::Result
137146 manifest. insert ( code_cid, t) ;
138147 }
139148 Err ( what) => {
140- return Err ( anyhow ! ( "bad builtin actor name: {}: {} " , name, what) ) ;
149+ return Err ( ManifestError :: BadBuiltinActor ( name, what) ) ;
141150 }
142151 }
143152 }
144153 Ok ( manifest)
145154}
155+
156+ #[ derive( thiserror:: Error , Debug ) ]
157+ pub enum ManifestError < BS : Blockstore > {
158+ #[ error( "unknown manifest version {0}" ) ]
159+ UnknownVersion ( u32 ) ,
160+ #[ error( "cannot find manifest root cid {0}" ) ]
161+ MissingRootCid ( Cid ) ,
162+ #[ error( "bad builtin actor name: {0}: {1}" ) ]
163+ BadBuiltinActor ( String , String ) ,
164+ #[ error( "encoding {0}" ) ]
165+ Encoding ( #[ from] CborStoreError < BS > ) ,
166+ }
0 commit comments