Skip to content

Commit

Permalink
Warn if external formatter is not found in validate command output
Browse files Browse the repository at this point in the history
  • Loading branch information
naiquevin committed Dec 28, 2024
1 parent bef59e2 commit 27b7812
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ impl Formatter {
};
res.map_err(Error::Io)
}

pub fn is_available(&self) -> bool {
match self {
Self::PgFormatter(f) => f.check(),
Self::SqlFormatRs(_) => true,
Self::SqlFormatter(f) => f.check(),
Self::SqlFluff(f) => f.check(),
}
}
}

/// Returns an ordered vec of formatters discovered on the system.
Expand Down
12 changes: 12 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ impl Metadata {
}
}

// Warn if the provided formatter is not found or installed on
// the system
if let Some(formatter) = self.formatter.as_ref() {
if !formatter.is_available() {
// @SAFE use of unwrap because if executable() returns
// None, it means the formatter is internal and hence
// will always be available.
let exec_path = formatter.executable().unwrap().display();
warn!("Executable for external formatter not found: {exec_path}");
}
}

Ok(())
}

Expand Down

0 comments on commit 27b7812

Please sign in to comment.