diff options
author | Daniel Schadt <kingdread@gmx.de> | 2019-12-10 14:48:54 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2019-12-10 14:48:54 +0100 |
commit | c86752e39dd015aa66c741be3e2312c6f0e69ef1 (patch) | |
tree | 893055684d534725fef986ea536569c1b8ccba24 | |
parent | 0c9276482d1508480ca247183853a31b762d25cf (diff) | |
download | kondou-c86752e39dd015aa66c741be3e2312c6f0e69ef1.tar.gz kondou-c86752e39dd015aa66c741be3e2312c6f0e69ef1.tar.bz2 kondou-c86752e39dd015aa66c741be3e2312c6f0e69ef1.zip |
avoid crashing with empty build templates
This would occur if e.g. only the profession was given.
-rw-r--r-- | src/main.rs | 16 | ||||
-rw-r--r-- | 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 <kingdread@gmx.de>") - .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<RgbaImage, RenderError> { let images = self.construct_parts(build)?; + if images.is_empty() { + return Err(RenderError::EmptyBuild); + } self.merge_parts(&images) } |