mirror of
https://github.com/denisidoro/navi
synced 2024-11-26 05:20:21 +00:00
Restructure error module
This commit is contained in:
parent
4bbccc2cfa
commit
11575a8443
5 changed files with 13 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::structures::error::FilesystemError;
|
||||
use crate::structures::error::filesystem::InvalidPath;
|
||||
use crate::structures::option::Config;
|
||||
use anyhow::Context;
|
||||
use anyhow::Error;
|
||||
|
@ -25,7 +25,7 @@ pub fn pathbuf_to_string(pathbuf: PathBuf) -> Result<String, Error> {
|
|||
Ok(pathbuf
|
||||
.as_os_str()
|
||||
.to_str()
|
||||
.ok_or_else(|| FilesystemError::InvalidPath(pathbuf.to_path_buf()))
|
||||
.ok_or_else(|| InvalidPath(pathbuf.to_path_buf()))
|
||||
.map(str::to_string)?)
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ fn follow_symlink(pathbuf: PathBuf) -> Result<PathBuf, Error> {
|
|||
let o_str = o
|
||||
.as_os_str()
|
||||
.to_str()
|
||||
.ok_or_else(|| FilesystemError::InvalidPath(o.to_path_buf()))?;
|
||||
.ok_or_else(|| InvalidPath(o.to_path_buf()))?;
|
||||
if o_str.starts_with('.') {
|
||||
let parent = pathbuf
|
||||
.parent()
|
||||
|
@ -53,7 +53,7 @@ fn follow_symlink(pathbuf: PathBuf) -> Result<PathBuf, Error> {
|
|||
let parent_str = parent
|
||||
.as_os_str()
|
||||
.to_str()
|
||||
.ok_or_else(|| FilesystemError::InvalidPath(parent.to_path_buf()))?;
|
||||
.ok_or_else(|| InvalidPath(parent.to_path_buf()))?;
|
||||
let path_str = format!("{}/{}", parent_str, o_str);
|
||||
let p = PathBuf::from(path_str);
|
||||
follow_symlink(p)
|
||||
|
@ -89,7 +89,7 @@ fn cheat_paths_from_config_dir() -> Result<String, Error> {
|
|||
path.path()
|
||||
.into_os_string()
|
||||
.to_str()
|
||||
.ok_or_else(|| FilesystemError::InvalidPath(path.path()))?,
|
||||
.ok_or_else(|| InvalidPath(path.path()))?,
|
||||
);
|
||||
paths_str.push_str(":");
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::filesystem;
|
|||
use crate::structures::cheat::VariableMap;
|
||||
use crate::structures::fnv::HashLine;
|
||||
use crate::structures::fzf::{Opts as FzfOpts, SuggestionType};
|
||||
use crate::structures::{error::FilesystemError, option::Config};
|
||||
use crate::structures::{error::filesystem::InvalidPath, option::Config};
|
||||
use crate::welcome;
|
||||
use anyhow::{Context, Error};
|
||||
use regex::Regex;
|
||||
|
@ -233,7 +233,7 @@ pub fn read_all(
|
|||
.path();
|
||||
let path_str = path
|
||||
.to_str()
|
||||
.ok_or_else(|| FilesystemError::InvalidPath(path.to_path_buf()))?;
|
||||
.ok_or_else(|| InvalidPath(path.to_path_buf()))?;
|
||||
if path_str.ends_with(".cheat")
|
||||
&& read_file(path_str, &mut variables, &mut visited_lines, stdin).is_ok()
|
||||
&& !found_something
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
use std::{fmt::Debug, path::PathBuf};
|
||||
use thiserror::Error;
|
||||
#[derive(Error, Debug)]
|
||||
pub enum FilesystemError {
|
||||
#[error("Invalid path `{0}`")]
|
||||
InvalidPath(PathBuf),
|
||||
}
|
5
src/structures/error/filesystem.rs
Normal file
5
src/structures/error/filesystem.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
use std::{fmt::Debug, path::PathBuf};
|
||||
use thiserror::Error;
|
||||
#[derive(Error, Debug)]
|
||||
#[error("Invalid path `{0}`")]
|
||||
pub struct InvalidPath(pub PathBuf);
|
1
src/structures/error/mod.rs
Normal file
1
src/structures/error/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod filesystem;
|
Loading…
Reference in a new issue