Skip to content

Commit

Permalink
Merge pull request #1287 from Barsik-sus/willbe_publish_fix_display_e…
Browse files Browse the repository at this point in the history
…rror

READY: (willbe): Improve error handling and reporting in modules
  • Loading branch information
Wandalen authored Apr 22, 2024
2 parents e15a6da + 0f419b0 commit 3a3029a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion module/move/willbe/src/action/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ mod private
None
};

let subgraph = graph::remove_not_required_to_publish( &package_map, &tmp, &packages_to_publish, dir.clone() );
let subgraph = graph::remove_not_required_to_publish( &package_map, &tmp, &packages_to_publish, dir.clone() ).err_with( || report.clone() )?;
let subgraph = subgraph.map( | _, n | n, | _, e | e );

let queue = graph::toposort( subgraph ).unwrap().into_iter().map( | n | package_map.get( &n ).unwrap() ).cloned().collect::< Vec< _ > >();
Expand Down
31 changes: 22 additions & 9 deletions module/move/willbe/src/entity/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod private
use former::Former;
use workspace::WorkspacePackage;
use diff::crate_diff;
use error_tools::for_app::Error;

///
#[ derive( Debug, Clone ) ]
Expand Down Expand Up @@ -301,6 +302,18 @@ mod private
pub commit : Option< process::Report >,
pub push : Option< process::Report >,
}

impl std::fmt::Display for ExtendedGitReport
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let Self { add, commit, push } = &self;
if let Some( add ) = add { writeln!( f, "{add}" )? }
if let Some( commit ) = commit { writeln!( f, "{commit}" )? }
if let Some( push ) = push { writeln!( f, "{push}" )? }

Ok( () )
}
}

#[ derive( Debug, Clone ) ]
pub struct GitThingsOptions
Expand All @@ -324,11 +337,11 @@ mod private
.with_context( || format!("git_root: {}, item: {}", o.git_root.as_ref().display(), item.as_ref().display() ) )
)
.collect::< Result< Vec< _ > > >()?;
let res = git::add( &o.git_root, &items, o.dry ).map_err( | e | format_err!( "{report:?}\n{e:#?}" ) )?;
let res = git::add( &o.git_root, &items, o.dry ).map_err( | e | format_err!( "{report}\n{e}" ) )?;
report.add = Some( res );
let res = git::commit( &o.git_root, &o.message, o.dry ).map_err( | e | format_err!( "{report:?}\n{e:#?}" ) )?;
let res = git::commit( &o.git_root, &o.message, o.dry ).map_err( | e | format_err!( "{report}\n{e}" ) )?;
report.commit = Some( res );
let res = git::push( &o.git_root, o.dry ).map_err( | e | format_err!( "{report:?}\n{e:#?}" ) )?;
let res = git::push( &o.git_root, o.dry ).map_err( | e | format_err!( "{report}\n{e}" ) )?;
report.push = Some( res );

Ok( report )
Expand Down Expand Up @@ -417,7 +430,7 @@ mod private
/// # Returns
///
/// * `Result<PublishReport>` - The result of the publishing operation, including information about the publish, version bump, and git operations.
pub fn perform_package_publish( instruction : PackagePublishInstruction ) -> Result< PublishReport >
pub fn perform_package_publish( instruction : PackagePublishInstruction ) -> Result< PublishReport, ( PublishReport, Error ) >
{
let mut report = PublishReport::default();
let PackagePublishInstruction
Expand All @@ -434,15 +447,15 @@ mod private
git_things.dry = dry;
publish.dry = dry;

report.get_info = Some( cargo::pack( pack ).map_err( | e | format_err!( "{report}\n{e:#?}" ) )? );
report.get_info = Some( cargo::pack( pack ).map_err( | e | ( report.clone(), e ) )? );
// qqq : redundant field?
report.publish_required = true;
report.bump = Some( version::version_bump( version_bump ).map_err( | e | format_err!( "{report}\n{e:#?}" ) )? );
let git = perform_git_operations( git_things ).map_err( |e | format_err!( "{report}\n{e:#?}" ) )?;
report.bump = Some( version::version_bump( version_bump ).map_err( | e | ( report.clone(), e ) )? );
let git = perform_git_operations( git_things ).map_err( | e | ( report.clone(), e ) )?;
report.add = git.add;
report.commit = git.commit;
report.push = git.push;
report.publish = Some( cargo::publish( publish ).map_err( | e | format_err!( "{report}\n{e:#?}" ) )? );
report.publish = Some( cargo::publish( publish ).map_err( | e | ( report.clone(), e ) )? );

Ok( report )
}
Expand Down Expand Up @@ -620,7 +633,7 @@ mod private
let mut report = vec![];
for package in plan.plans
{
let res = perform_package_publish( package ).map_err( | e | format_err!( "{report:#?}\n{e:#?}" ) )?;
let res = perform_package_publish( package ).map_err( |( current_rep, e )| format_err!( "{}\n{current_rep}\n{e}", report.iter().map( | r | format!( "{r}" ) ).join( "\n" ) ) )?;
report.push( res );
}

Expand Down
7 changes: 4 additions & 3 deletions module/move/willbe/src/tool/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub( crate ) mod private
use petgraph::prelude::*;

use error_tools::for_lib::Error;
use error::Result;
use package::{ Package, publish_need };

#[ derive( Debug, Error ) ]
Expand Down Expand Up @@ -242,7 +243,7 @@ pub( crate ) mod private
roots : &[ String ],
temp_path : Option< PathBuf >,
)
-> Graph< String, String >
-> Result< Graph< String, String > >
{
let mut nodes = HashSet::new();
let mut cleared_graph = Graph::new();
Expand All @@ -269,7 +270,7 @@ pub( crate ) mod private
.option_temp_path( temp_path.clone() )
.dry( false )
.form()
).unwrap();
)?;
if publish_need( package, temp_path.clone() ).unwrap()
{
nodes.insert( n );
Expand All @@ -294,7 +295,7 @@ pub( crate ) mod private
}
}

cleared_graph
Ok( cleared_graph )
}
}

Expand Down

0 comments on commit 3a3029a

Please sign in to comment.