aboutsummaryrefslogtreecommitdiff
path: root/src/archiver
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-03-09 15:34:57 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2024-03-09 15:34:57 +0100
commit50f53dc480fda8b3daab7a34454c2dd9f3f5f991 (patch)
tree2205be7a9c806ce59c851de9b50b9e18f973008d /src/archiver
parent172f4c8807d44ebe38c7f227b7fdc2d6a9dbe323 (diff)
Improve the error handlingrust
Diffstat (limited to 'src/archiver')
-rw-r--r--src/archiver/gemini.rs7
-rw-r--r--src/archiver/gopher.rs7
2 files changed, 8 insertions, 6 deletions
diff --git a/src/archiver/gemini.rs b/src/archiver/gemini.rs
index 8d56305..3b04bcf 100644
--- a/src/archiver/gemini.rs
+++ b/src/archiver/gemini.rs
@@ -1,5 +1,5 @@
use std::fs::write;
-use std::io::Result;
+use std::io::{Error, ErrorKind::Other, Result};
use std::path::PathBuf;
use crate::template::{find, parse, TemplateContext};
@@ -8,8 +8,9 @@ const FILENAME: &str = "index.gmi";
pub fn archive(_: &PathBuf, template_directory: &PathBuf, target: &PathBuf, context: &TemplateContext) -> Result<()> {
match find(template_directory, FILENAME) {
Some(template) => {
- let parsed_template = parse(&template);
- let rendered_template = parsed_template.render(context);
+ let parsed_template = parse(&template)
+ .ok_or_else(|| Error::new(Other, "Unable to parse Gemini Archive template"))?;
+ let rendered_template = parsed_template.render(context)?;
let location = target.join(FILENAME);
write(location, rendered_template)?;
},
diff --git a/src/archiver/gopher.rs b/src/archiver/gopher.rs
index 820e4d1..28f4f46 100644
--- a/src/archiver/gopher.rs
+++ b/src/archiver/gopher.rs
@@ -1,5 +1,5 @@
use std::fs::write;
-use std::io::Result;
+use std::io::{Error, ErrorKind::Other, Result};
use std::path::PathBuf;
use crate::template::{find, parse, TemplateContext};
@@ -8,8 +8,9 @@ const FILENAME: &str = "index.gph";
pub fn archive(_: &PathBuf, template_directory: &PathBuf, target: &PathBuf, context: &TemplateContext) -> Result<()> {
match find(template_directory, FILENAME) {
Some(template) => {
- let parsed_template = parse(&template);
- let rendered_template = parsed_template.render(context);
+ let parsed_template = parse(&template)
+ .ok_or_else(|| Error::new(Other, "Unable to parse Gopher Archive template"))?;
+ let rendered_template = parsed_template.render(context)?;
let location = target.join(FILENAME);
write(location, rendered_template)?;
},