Skip to content

Commit

Permalink
fix: Dont panic on missing file path
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed May 21, 2024
1 parent 2ab407b commit fb34276
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/history.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use std::path::{Path, PathBuf};

use anyhow::Context;

#[derive(Debug, Clone, PartialEq)]
pub struct History {
history: Vec<PathBuf>,
index: usize,
}

impl History {
pub fn new(path: &Path) -> Self {
let canonicalized = path.canonicalize().unwrap();
Self {
pub fn new(path: &Path) -> anyhow::Result<Self> {
let canonicalized = path
.canonicalize()
.with_context(|| format!("Unable to canonicalize {}", path.display()))?;
Ok(Self {
history: vec![canonicalized],
index: 0,
}
})
}

pub fn get_path(&self) -> &Path {
Expand Down
3 changes: 2 additions & 1 deletion src/opts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl Opts {

set_render_element_bounds(render_element_bounds);

let history = History::new(&file_path)?;
let resolved_theme = args_theme
.or(config_theme)
.and_then(ResolvedTheme::new)
Expand Down Expand Up @@ -157,7 +158,7 @@ impl Opts {
};

Ok(Self {
history: History::new(&file_path),
history,
theme,
scale,
page_width,
Expand Down

0 comments on commit fb34276

Please sign in to comment.