diff --git a/src/formatters/mod.rs b/src/formatters/mod.rs index 7b3802f..18dc2d1 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -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. diff --git a/src/metadata.rs b/src/metadata.rs index 801a72a..b70d121 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -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(()) }