11use crate :: {
22 autorust_toml, cargo_toml, io, lib_rs,
33 readme_md:: { self , ReadmeMd } ,
4- run, CrateConfig , Error , Result , RunConfig , SpecReadme ,
4+ run, CrateConfig , Error , ErrorKind , Result , ResultExt , RunConfig , SpecReadme ,
55} ;
66use std:: { collections:: HashMap , fs} ;
77
@@ -54,21 +54,26 @@ pub fn gen_crate(package_name: &str, spec: &SpecReadme, run_config: &RunConfig,
5454 let mut api_versions = HashMap :: new ( ) ;
5555 let mut has_xml = false ;
5656 for tag in tags {
57- generated_tags. push ( tag. name ( ) . to_owned ( ) ) ;
57+ let name = tag. name ( ) ;
58+ generated_tags. push ( name. to_owned ( ) ) ;
5859 let output_folder = io:: join ( & src_folder, tag. rust_mod_name ( ) ) ?;
5960 let input_files: Result < Vec < _ > > = tag
6061 . input_files ( )
6162 . iter ( )
6263 . map ( |input_file| io:: join ( spec. readme ( ) , input_file) . map_err ( Error :: from) )
6364 . collect ( ) ;
64- let input_files = input_files?;
65+ let input_files = input_files. with_context ( ErrorKind :: CodeGen , || format ! ( "collecting input files for tag {name}" ) ) ?;
66+
6567 let crate_config = & CrateConfig {
6668 run_config,
6769 output_folder,
6870 input_files,
6971 } ;
70- let cg = run ( crate_config, & package_config) ?;
71- let operations = cg. spec . operations ( ) ?;
72+ let cg = run ( crate_config, & package_config) . with_context ( ErrorKind :: CodeGen , || format ! ( "gen_crate run for tag {name}" ) ) ?;
73+ let operations = cg
74+ . spec
75+ . operations ( )
76+ . with_context ( ErrorKind :: CodeGen , || format ! ( "gen_crate operations for tag {name}" ) ) ?;
7277 operation_totals. insert ( tag. name ( ) , operations. len ( ) ) ;
7378 let mut versions = cg. spec . api_versions ( ) ;
7479 versions. sort_unstable ( ) ;
@@ -84,8 +89,8 @@ pub fn gen_crate(package_name: &str, spec: &SpecReadme, run_config: &RunConfig,
8489 } ;
8590 let default_tag = cargo_toml:: get_default_tag ( tags, default_tag_name) ;
8691
87- cargo_toml:: create ( package_name, tags, default_tag, has_xml, & cargo_toml_path) ?;
88- lib_rs:: create ( tags, lib_rs_path, false ) ?;
92+ cargo_toml:: create ( package_name, tags, default_tag, has_xml, & cargo_toml_path) . context ( ErrorKind :: CodeGen , "cargo_toml::create" ) ?;
93+ lib_rs:: create ( tags, lib_rs_path, false ) . context ( ErrorKind :: CodeGen , "lib_rs::create" ) ?;
8994 let readme = ReadmeMd {
9095 package_name,
9196 readme_url : readme_md:: url ( spec. readme ( ) . as_str ( ) ) ,
@@ -95,7 +100,7 @@ pub fn gen_crate(package_name: &str, spec: &SpecReadme, run_config: &RunConfig,
95100 api_version_totals,
96101 api_versions,
97102 } ;
98- readme. create ( & readme_path) ?;
103+ readme. create ( & readme_path) . context ( ErrorKind :: CodeGen , "readme::create" ) ?;
99104
100105 Ok ( generated_tags)
101106}
0 commit comments