fix(cli): fix panic when no paths are provided (#944)

This commit is contained in:
Cameron 2023-09-30 09:05:55 +01:00 committed by GitHub
parent 86b483518b
commit d5b70c3b2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View file

@ -33,6 +33,10 @@ impl Runner for LintRunner {
misc_options,
} = self.options;
if paths.is_empty() {
return CliRunResult::InvalidOptions { message: "No paths provided.".to_string() };
}
let now = std::time::Instant::now();
let paths = Walk::new(&paths, &ignore_options).paths();

View file

@ -7,6 +7,7 @@ use std::{
#[derive(Debug)]
pub enum CliRunResult {
None,
InvalidOptions { message: String },
PathNotFound { paths: Vec<PathBuf> },
LintResult(LintResult),
TypeCheckResult { duration: Duration, number_of_diagnostics: usize },
@ -26,6 +27,10 @@ impl Termination for CliRunResult {
fn report(self) -> ExitCode {
match self {
Self::None => ExitCode::from(0),
Self::InvalidOptions { message } => {
println!("Invalid Options: {message}");
ExitCode::from(1)
}
Self::PathNotFound { paths } => {
println!("Path {paths:?} does not exist.");
ExitCode::from(1)

View file

@ -52,6 +52,8 @@ impl ignore::ParallelVisitor for WalkCollector {
impl Walk {
/// # Panics
pub fn new(paths: &[PathBuf], options: &IgnoreOptions) -> Self {
assert!(!paths.is_empty(), "At least one path must be provided to Walk::new");
let paths = paths
.iter()
.map(|p| p.canonicalize().unwrap_or_else(|_| p.clone()))