mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: improve error handling in config file reading (#2901)
This commit is contained in:
parent
f5d0f47b51
commit
3a9591a3d9
4 changed files with 13 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use anyhow::Result;
|
||||
use anyhow::{Context, Result};
|
||||
use serde::Deserialize;
|
||||
use yazi_codegen::DeserializeOver1;
|
||||
use yazi_fs::{Xdg, ok_or_not_found};
|
||||
|
|
@ -38,7 +38,9 @@ impl Keymap {
|
|||
|
||||
impl Keymap {
|
||||
pub(crate) fn read() -> Result<String> {
|
||||
Ok(ok_or_not_found(std::fs::read_to_string(Xdg::config_dir().join("keymap.toml")))?)
|
||||
let p = Xdg::config_dir().join("keymap.toml");
|
||||
ok_or_not_found(std::fs::read_to_string(&p))
|
||||
.with_context(|| format!("Failed to read keymap {p:?}"))
|
||||
}
|
||||
|
||||
pub(crate) fn reshape(self) -> Result<Self> {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl Flavor {
|
|||
"" => String::new(),
|
||||
name => {
|
||||
let p = Xdg::config_dir().join(format!("flavors/{name}.yazi/flavor.toml"));
|
||||
std::fs::read_to_string(&p).with_context(|| format!("Failed to load flavor {p:?}"))?
|
||||
std::fs::read_to_string(&p).with_context(|| format!("Failed to read flavor {p:?}"))?
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use serde::Deserialize;
|
||||
use yazi_codegen::{DeserializeOver1, DeserializeOver2};
|
||||
use yazi_fs::{Xdg, expand_path, ok_or_not_found};
|
||||
|
|
@ -207,7 +207,9 @@ pub struct Help {
|
|||
|
||||
impl Theme {
|
||||
pub(crate) fn read() -> Result<String> {
|
||||
Ok(ok_or_not_found(std::fs::read_to_string(Xdg::config_dir().join("theme.toml")))?)
|
||||
let p = Xdg::config_dir().join("theme.toml");
|
||||
ok_or_not_found(std::fs::read_to_string(&p))
|
||||
.with_context(|| format!("Failed to read theme {p:?}"))
|
||||
}
|
||||
|
||||
pub(crate) fn reshape(mut self, light: bool) -> Result<Self> {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use anyhow::Result;
|
||||
use anyhow::{Context, Result};
|
||||
use serde::Deserialize;
|
||||
use yazi_codegen::DeserializeOver1;
|
||||
use yazi_fs::{Xdg, ok_or_not_found};
|
||||
|
|
@ -21,7 +21,9 @@ pub struct Yazi {
|
|||
|
||||
impl Yazi {
|
||||
pub(super) fn read() -> Result<String> {
|
||||
Ok(ok_or_not_found(std::fs::read_to_string(Xdg::config_dir().join("yazi.toml")))?)
|
||||
let p = Xdg::config_dir().join("yazi.toml");
|
||||
ok_or_not_found(std::fs::read_to_string(&p))
|
||||
.with_context(|| format!("Failed to read config {p:?}"))
|
||||
}
|
||||
|
||||
pub(super) fn reshape(self) -> Result<Self> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue