mirror of
https://github.com/numtide/treefmt.git
synced 2024-09-11 17:07:44 +03:00
cache: soft failure on manifest loading issue
If the manifest couldn't be loaded it's probably that the file format has changed. Ignore the error and continue.
This commit is contained in:
parent
3bb40df07f
commit
bde7493591
@ -15,12 +15,20 @@ use std::process::Command;
|
||||
pub fn run_treefmt(cwd: PathBuf, cache_dir: PathBuf, treefmt_toml: PathBuf) -> anyhow::Result<()> {
|
||||
let project_config = config::from_path(&treefmt_toml)?;
|
||||
|
||||
// Load the manifest if it exists, otherwise print the error and use an empty manifest
|
||||
let mfst: RootManifest = match read_manifest(&treefmt_toml, &cache_dir) {
|
||||
Ok(mfst) => mfst,
|
||||
Err(err) => {
|
||||
CLOG.warn(&format!("Using empty manifest due to error: {}", err));
|
||||
RootManifest::default()
|
||||
}
|
||||
};
|
||||
|
||||
// Once the treefmt found the $XDG_CACHE_DIR/treefmt/eval-cache/ folder,
|
||||
// it will try to scan the manifest and passed it into check_treefmt function
|
||||
let old_ctx = create_command_context(&cwd, &project_config)?;
|
||||
// TODO: Resolve all of the formatters paths. If missing, print an error, remove the formatters from the list and continue.
|
||||
// Load the manifest if it exists, otherwise start with empty manifest
|
||||
let mfst: RootManifest = read_manifest(&treefmt_toml, &cache_dir)?;
|
||||
|
||||
// Compare the list of files with the manifest, keep the ones that are not in the manifest
|
||||
let ctxs = check_treefmt(&treefmt_toml, &old_ctx, &mfst)?;
|
||||
let context = if mfst.manifest.is_empty() && ctxs.is_empty() {
|
||||
|
@ -9,12 +9,13 @@ use std::fs::{read_to_string, File};
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
/// RootManifest
|
||||
pub struct RootManifest {
|
||||
/// Map of manifests config based on its formatter
|
||||
pub manifest: BTreeMap<String, CmdContext>,
|
||||
}
|
||||
|
||||
/// Create <hex(hash(path-to-treefmt))>.toml and put it in $XDG_CACHE_DIR/treefmt/eval-cache/
|
||||
pub fn create_manifest(
|
||||
treefmt_toml: PathBuf,
|
||||
|
Loading…
Reference in New Issue
Block a user