From c86752e39dd015aa66c741be3e2312c6f0e69ef1 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 10 Dec 2019 14:48:54 +0100 Subject: avoid crashing with empty build templates This would occur if e.g. only the profession was given. --- src/main.rs | 16 ++++++++-------- src/render.rs | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index d928c09..6194ef0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -226,8 +226,8 @@ fn validate_legend(input: String) -> Result<(), String> { fn run() -> MainResult<()> { let matches = App::new(APP_NAME) .version("0.1") - .author("Daniel ") - .about("Renders GW2 skills and traits.") + .author("Peter Parker IV") + .about("Renders Guild Wars 2 skills and traits.") .arg( Arg::with_name("profession") .help("Selects which profession to use.") @@ -304,12 +304,12 @@ fn run() -> MainResult<()> { } let mut renderer = render::Renderer::new(&mut api, Default::default()); - let img = renderer.render_buildtemplate(&build).unwrap(); - let filename = matches.value_of("outfile").unwrap(); - img.save(filename)?; - - if !matches.is_present("quiet") { - println!("Image saved in {}", filename); + if let Ok(img) = renderer.render_buildtemplate(&build) { + let filename = matches.value_of("outfile").unwrap(); + img.save(filename)?; + if !matches.is_present("quiet") { + println!("Image saved in {}", filename); + } } Ok(()) diff --git a/src/render.rs b/src/render.rs index bb38399..90eff14 100644 --- a/src/render.rs +++ b/src/render.rs @@ -19,6 +19,9 @@ quick_error! { cause(err) from() } + EmptyBuild { + description("The build template contains nothing worth rendering") + } } } @@ -284,6 +287,9 @@ impl<'r> Renderer<'r> { build: &BuildTemplate, ) -> Result { let images = self.construct_parts(build)?; + if images.is_empty() { + return Err(RenderError::EmptyBuild); + } self.merge_parts(&images) } -- cgit v1.2.3