diff --git a/CHANGELOG.md b/CHANGELOG.md index 63b5b241..c3160208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ - `--map-syntax` doesn't work with names provided through `--file-name` (@eth-p) ## Other + +- bat now prints an error if an invalid syntax is specified (@sharkdp) + ## New syntaxes ## New themes ## `bat` as a library diff --git a/src/controller.rs b/src/controller.rs index a7f2f3c0..e11080f5 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -121,7 +121,7 @@ impl<'b> Controller<'b> { &mut opened_input, #[cfg(feature = "git")] &line_changes, - )) + )?) }; let result = self.print_file( diff --git a/src/printer.rs b/src/printer.rs index 41d298c6..d1260c74 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -112,7 +112,7 @@ impl<'a> InteractivePrinter<'a> { assets: &'a HighlightingAssets, input: &mut OpenedInput, #[cfg(feature = "git")] line_changes: &'a Option, - ) -> Self { + ) -> Result { let theme = assets.get_theme(&config.theme); let background_color_highlight = theme.settings.line_highlight; @@ -164,14 +164,18 @@ impl<'a> InteractivePrinter<'a> { None } else { // Determine the type of syntax for highlighting - let syntax = assets - .get_syntax(config.language, input, &config.syntax_mapping) - .unwrap_or_else(|_| assets.syntax_set.find_syntax_plain_text()); + let syntax = match assets.get_syntax(config.language, input, &config.syntax_mapping) { + Ok(syntax) => syntax, + Err(Error(ErrorKind::UndetectedSyntax(_), _)) => { + assets.syntax_set.find_syntax_plain_text() + } + Err(e) => return Err(e), + }; Some(HighlightLines::new(syntax, theme)) }; - InteractivePrinter { + Ok(InteractivePrinter { panel_width, colors, config, @@ -183,7 +187,7 @@ impl<'a> InteractivePrinter<'a> { highlighter, syntax_set: &assets.syntax_set, background_color_highlight, - } + }) } fn print_horizontal_line(&mut self, handle: &mut dyn Write, grid_char: char) -> Result<()> {