Skip to content

Commit c74cc9d

Browse files
authored
Merge pull request #1157 from Turbo87/eyre
Use `eyre` for error handling
2 parents 357ed1b + 10d0287 commit c74cc9d

File tree

6 files changed

+176
-24
lines changed

6 files changed

+176
-24
lines changed

Cargo.lock

Lines changed: 155 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ name = "blog"
99
path = "src/blog.rs"
1010

1111
[dependencies]
12+
color-eyre = "0.6.2"
13+
eyre = "0.6.8"
1214
handlebars = { version = "3", features = ["dir_source"] }
1315
lazy_static = "1.4.0"
1416
serde = "1.0"

src/blog.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::error::Error;
2-
31
#[path = "lib.rs"]
42
mod lib;
53

6-
pub fn main() -> Result<(), Box<dyn Error>> {
4+
pub fn main() -> eyre::Result<()> {
5+
color_eyre::install()?;
6+
77
lib::main()?;
88

99
println!("blog has been generated; you can now serve its content by running\n\

src/blogs.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::posts::Post;
22
use serde_derive::{Deserialize, Serialize};
3-
use std::error::Error;
43
use std::path::{Path, PathBuf};
54

65
static MANIFEST_FILE: &str = "blog.yml";
@@ -46,7 +45,7 @@ pub(crate) struct Blog {
4645
}
4746

4847
impl Blog {
49-
fn load(prefix: PathBuf, dir: &Path) -> Result<Self, Box<dyn Error>> {
48+
fn load(prefix: PathBuf, dir: &Path) -> eyre::Result<Self> {
5049
let manifest_content = std::fs::read_to_string(dir.join(MANIFEST_FILE))?;
5150
let manifest: Manifest = serde_yaml::from_str(&manifest_content)?;
5251

@@ -122,7 +121,7 @@ impl Blog {
122121

123122
/// Recursively load blogs in a directory. A blog is a directory with a `blog.yml`
124123
/// file inside it.
125-
pub(crate) fn load(base: &Path) -> Result<Vec<Blog>, Box<dyn Error>> {
124+
pub(crate) fn load(base: &Path) -> eyre::Result<Vec<Blog>> {
126125
let mut blogs = Vec::new();
127126
load_recursive(base, base, &mut blogs)?;
128127
Ok(blogs)
@@ -132,7 +131,7 @@ fn load_recursive(
132131
base: &Path,
133132
current: &Path,
134133
blogs: &mut Vec<Blog>,
135-
) -> Result<(), Box<dyn Error>> {
134+
) -> eyre::Result<()> {
136135
for entry in std::fs::read_dir(current)? {
137136
let path = entry?.path();
138137
let file_type = path.metadata()?.file_type();

0 commit comments

Comments
 (0)