mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Make main.rs robust to cache initialization failures (#831)
This commit is contained in:
parent
529513bf02
commit
5bf8219db3
1 changed files with 14 additions and 8 deletions
22
src/main.rs
22
src/main.rs
|
@ -286,7 +286,7 @@ fn inner_main() -> Result<ExitCode> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract settings for internal use.
|
// Extract settings for internal use.
|
||||||
let autofix = configuration.fix;
|
let fix_enabled: bool = configuration.fix;
|
||||||
let settings = Settings::from_configuration(configuration);
|
let settings = Settings::from_configuration(configuration);
|
||||||
|
|
||||||
if cli.show_files {
|
if cli.show_files {
|
||||||
|
@ -294,12 +294,18 @@ fn inner_main() -> Result<ExitCode> {
|
||||||
return Ok(ExitCode::SUCCESS);
|
return Ok(ExitCode::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the cache.
|
||||||
|
let mut cache_enabled: bool = !cli.no_cache;
|
||||||
|
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
cache::init()?;
|
if cache_enabled && cache::init().is_err() {
|
||||||
|
eprintln!("Unable to initialize cache; disabling...");
|
||||||
|
cache_enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
let printer = Printer::new(&cli.format, &log_level);
|
let printer = Printer::new(&cli.format, &log_level);
|
||||||
if cli.watch {
|
if cli.watch {
|
||||||
if autofix {
|
if fix_enabled {
|
||||||
eprintln!("Warning: --fix is not enabled in watch mode.");
|
eprintln!("Warning: --fix is not enabled in watch mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +325,7 @@ fn inner_main() -> Result<ExitCode> {
|
||||||
printer.clear_screen()?;
|
printer.clear_screen()?;
|
||||||
printer.write_to_user("Starting linter in watch mode...\n");
|
printer.write_to_user("Starting linter in watch mode...\n");
|
||||||
|
|
||||||
let messages = run_once(&cli.files, &settings, !cli.no_cache, false)?;
|
let messages = run_once(&cli.files, &settings, cache_enabled, false)?;
|
||||||
printer.write_continuously(&messages)?;
|
printer.write_continuously(&messages)?;
|
||||||
|
|
||||||
// Configure the file watcher.
|
// Configure the file watcher.
|
||||||
|
@ -337,7 +343,7 @@ fn inner_main() -> Result<ExitCode> {
|
||||||
printer.clear_screen()?;
|
printer.clear_screen()?;
|
||||||
printer.write_to_user("File change detected...\n");
|
printer.write_to_user("File change detected...\n");
|
||||||
|
|
||||||
let messages = run_once(&cli.files, &settings, !cli.no_cache, false)?;
|
let messages = run_once(&cli.files, &settings, cache_enabled, false)?;
|
||||||
printer.write_continuously(&messages)?;
|
printer.write_continuously(&messages)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -362,15 +368,15 @@ fn inner_main() -> Result<ExitCode> {
|
||||||
let messages = if is_stdin {
|
let messages = if is_stdin {
|
||||||
let filename = cli.stdin_filename.unwrap_or_else(|| "-".to_string());
|
let filename = cli.stdin_filename.unwrap_or_else(|| "-".to_string());
|
||||||
let path = Path::new(&filename);
|
let path = Path::new(&filename);
|
||||||
run_once_stdin(&settings, path, autofix)?
|
run_once_stdin(&settings, path, fix_enabled)?
|
||||||
} else {
|
} else {
|
||||||
run_once(&cli.files, &settings, !cli.no_cache, autofix)?
|
run_once(&cli.files, &settings, cache_enabled, fix_enabled)?
|
||||||
};
|
};
|
||||||
|
|
||||||
// Always try to print violations (the printer itself may suppress output),
|
// Always try to print violations (the printer itself may suppress output),
|
||||||
// unless we're writing fixes via stdin (in which case, the transformed
|
// unless we're writing fixes via stdin (in which case, the transformed
|
||||||
// source code goes to stdout).
|
// source code goes to stdout).
|
||||||
if !(is_stdin && autofix) {
|
if !(is_stdin && fix_enabled) {
|
||||||
printer.write_once(&messages)?;
|
printer.write_once(&messages)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue