From 807d6cdf2d5585a7499a29c29c7aade2883b0e28 Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Fri, 5 Apr 2024 15:32:14 +0200 Subject: [PATCH 1/2] feat: log if formatter error --- src/error.rs | 2 ++ src/formatters/alejandra.rs | 3 ++- src/formatters/autopep8.rs | 3 ++- src/formatters/beautysh.rs | 3 ++- src/formatters/biome.rs | 4 ++-- src/formatters/black.rs | 3 ++- src/formatters/blade_formatter.rs | 6 +++--- src/formatters/blue.rs | 3 ++- src/formatters/buf.rs | 5 ++++- src/formatters/cabal_format.rs | 3 ++- src/formatters/clang_format.rs | 3 ++- src/formatters/cljstyle.rs | 3 ++- src/formatters/crystal_format.rs | 3 ++- src/formatters/csharpier.rs | 3 ++- src/formatters/dart_format.rs | 3 ++- src/formatters/deno_fmt.rs | 3 ++- src/formatters/efmt.rs | 3 ++- src/formatters/elm_format.rs | 6 +++--- src/formatters/erlfmt.rs | 5 ++++- src/formatters/fantomas.rs | 3 ++- src/formatters/fourmolu.rs | 3 ++- src/formatters/gleam_format.rs | 3 ++- src/formatters/gofmt.rs | 3 ++- src/formatters/gofumpt.rs | 3 ++- src/formatters/goimports.rs | 3 ++- src/formatters/google_java_format.rs | 3 ++- src/formatters/hindent.rs | 3 ++- src/formatters/isort.rs | 3 ++- src/formatters/juliaformatter_jl.rs | 3 ++- src/formatters/just_fmt.rs | 3 ++- src/formatters/ktfmt.rs | 3 ++- src/formatters/ktlint.rs | 3 ++- src/formatters/luaformatter.rs | 3 ++- src/formatters/mix_format.rs | 3 ++- src/formatters/mod.rs | 31 +++++++++++++++------------- src/formatters/nimpretty.rs | 3 ++- src/formatters/nixfmt.rs | 3 ++- src/formatters/nixpkgs_fmt.rs | 3 ++- src/formatters/npm_groovy_lint.rs | 6 +++--- src/formatters/ocamlformat.rs | 3 ++- src/formatters/ocp_indent.rs | 3 ++- src/formatters/ormolu.rs | 3 ++- src/formatters/perltidy.rs | 5 +++-- src/formatters/prettier.rs | 11 ++++++---- src/formatters/purs_tidy.rs | 6 +++--- src/formatters/rescript_format.rs | 6 +++--- src/formatters/roc_format.rs | 3 ++- src/formatters/rubocop.rs | 3 ++- src/formatters/rubyfmt.rs | 3 ++- src/formatters/ruff.rs | 3 ++- src/formatters/rufo.rs | 3 ++- src/formatters/rustfmt.rs | 5 +++-- src/formatters/scalafmt.rs | 3 ++- src/formatters/shfmt.rs | 5 ++++- src/formatters/sql_formatter.rs | 6 +++--- src/formatters/sqlfluff.rs | 5 +++-- src/formatters/standardjs.rs | 6 +++--- src/formatters/standardrb.rs | 3 ++- src/formatters/stylelint.rs | 6 +++--- src/formatters/stylish_haskell.rs | 3 ++- src/formatters/stylua.rs | 6 +++--- src/formatters/swift_format.rs | 3 ++- src/formatters/swiftformat.rs | 3 ++- src/formatters/taplo.rs | 6 +++--- src/formatters/terraform_fmt.rs | 3 ++- src/formatters/tofu_fmt.rs | 3 ++- src/formatters/usort.rs | 3 ++- src/formatters/xmlformat.rs | 3 ++- src/formatters/xmllint.rs | 3 ++- src/formatters/yamlfix.rs | 3 ++- src/formatters/yamlfmt.rs | 3 ++- src/formatters/yapf.rs | 3 ++- src/formatters/zigfmt.rs | 3 ++- src/languages/blade.rs | 7 +++++-- src/languages/c.rs | 7 +++++-- src/languages/cabal.rs | 7 +++++-- src/languages/clojure.rs | 7 +++++-- src/languages/cpp.rs | 7 +++++-- src/languages/crystal.rs | 7 +++++-- src/languages/csharp.rs | 9 +++++--- src/languages/css.rs | 9 +++++--- src/languages/dart.rs | 7 +++++-- src/languages/elixir.rs | 7 +++++-- src/languages/elm.rs | 7 +++++-- src/languages/erlang.rs | 7 +++++-- src/languages/fsharp.rs | 7 +++++-- src/languages/gleam.rs | 7 +++++-- src/languages/go.rs | 11 ++++++---- src/languages/graphql.rs | 7 +++++-- src/languages/groovy.rs | 7 +++++-- src/languages/haskell.rs | 11 ++++++---- src/languages/hcl.rs | 9 +++++--- src/languages/html.rs | 7 +++++-- src/languages/java.rs | 11 ++++++---- src/languages/javascript.rs | 13 +++++++----- src/languages/json.rs | 11 ++++++---- src/languages/julia.rs | 7 +++++-- src/languages/just.rs | 7 +++++-- src/languages/kotlin.rs | 7 +++++-- src/languages/lua.rs | 9 +++++--- src/languages/markdown.rs | 7 +++++-- src/languages/mod.rs | 28 ++++++++++++++++++------- src/languages/nim.rs | 7 +++++-- src/languages/nix.rs | 11 ++++++---- src/languages/objective_c.rs | 7 +++++-- src/languages/ocaml.rs | 9 +++++--- src/languages/perl.rs | 7 +++++-- src/languages/protobuf.rs | 7 ++++--- src/languages/purescript.rs | 7 +++++-- src/languages/python.rs | 13 +++++++----- src/languages/rescript.rs | 7 +++++-- src/languages/roc.rs | 7 +++++-- src/languages/ruby.rs | 11 ++++++---- src/languages/rust.rs | 7 +++++-- src/languages/scala.rs | 7 +++++-- src/languages/shell.rs | 7 ++++--- src/languages/sql.rs | 9 +++++--- src/languages/swift.rs | 10 ++++++--- src/languages/toml.rs | 7 +++++-- src/languages/typescript.rs | 11 ++++++---- src/languages/vue.rs | 7 +++++-- src/languages/xml.rs | 7 ++++--- src/languages/yaml.rs | 11 ++++++---- src/languages/zig.rs | 7 +++++-- src/terminal/logging.rs | 4 +++- src/terminal/mod.rs | 8 +++++++ 126 files changed, 494 insertions(+), 252 deletions(-) diff --git a/src/error.rs b/src/error.rs index 9e36715d..ee77e2e7 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,6 +4,7 @@ pub enum MdsfError { Fmt(core::fmt::Error), ConfigParse(std::path::PathBuf), FileNotFound(std::path::PathBuf), + FormatterError, } impl core::fmt::Display for MdsfError { @@ -20,6 +21,7 @@ impl core::fmt::Display for MdsfError { "No file or directory with the name '{}' found", path.display() )), + Self::FormatterError => f.write_str("Error formatting"), } } } diff --git a/src/formatters/alejandra.rs b/src/formatters/alejandra.rs index cc2ff25c..495360b9 100644 --- a/src/formatters/alejandra.rs +++ b/src/formatters/alejandra.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_alejandra( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("alejandra"); cmd.arg("--quiet").arg(snippet_path); diff --git a/src/formatters/autopep8.rs b/src/formatters/autopep8.rs index a5af9670..1d57f69b 100644 --- a/src/formatters/autopep8.rs +++ b/src/formatters/autopep8.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_autopep8( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("autopep8"); cmd.arg("--in-place").arg(snippet_path); diff --git a/src/formatters/beautysh.rs b/src/formatters/beautysh.rs index 0e5aabed..539a86ae 100644 --- a/src/formatters/beautysh.rs +++ b/src/formatters/beautysh.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_beautysh( file_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("beautysh"); cmd.arg(file_path); diff --git a/src/formatters/biome.rs b/src/formatters/biome.rs index 4e5c6a11..2c6f3029 100644 --- a/src/formatters/biome.rs +++ b/src/formatters/biome.rs @@ -1,10 +1,10 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] pub fn format_using_biome( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { // NOTE: the biome docs recommend running biome using npx, and not directly let mut cmd = setup_npm_script("@biomejs/biome"); diff --git a/src/formatters/black.rs b/src/formatters/black.rs index 8f9fb121..b8ed169e 100644 --- a/src/formatters/black.rs +++ b/src/formatters/black.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_black( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("black"); cmd.arg("--quiet").arg(snippet_path); diff --git a/src/formatters/blade_formatter.rs b/src/formatters/blade_formatter.rs index 0e491d02..b1b86900 100644 --- a/src/formatters/blade_formatter.rs +++ b/src/formatters/blade_formatter.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_blade_formatter_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -10,7 +10,7 @@ fn set_blade_formatter_args(cmd: &mut std::process::Command, snippet_path: &std: fn invote_blade_formatter( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_blade_formatter_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -19,7 +19,7 @@ fn invote_blade_formatter( #[inline] pub fn format_using_blade_formatter( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { invote_blade_formatter(setup_npm_script("blade-formatter"), snippet_path) } diff --git a/src/formatters/blue.rs b/src/formatters/blue.rs index 1ccc86e0..e5a0c02f 100644 --- a/src/formatters/blue.rs +++ b/src/formatters/blue.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_blue( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("blue"); cmd.arg("--quiet").arg(snippet_path); diff --git a/src/formatters/buf.rs b/src/formatters/buf.rs index e9988ced..9fa51b3d 100644 --- a/src/formatters/buf.rs +++ b/src/formatters/buf.rs @@ -1,7 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] -pub fn format_using_buf(snippet_path: &std::path::Path) -> std::io::Result<(bool, Option)> { +pub fn format_using_buf( + snippet_path: &std::path::Path, +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("buf"); cmd.arg("format").arg("--write").arg(snippet_path); diff --git a/src/formatters/cabal_format.rs b/src/formatters/cabal_format.rs index 4a1868aa..90df8d42 100644 --- a/src/formatters/cabal_format.rs +++ b/src/formatters/cabal_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_cabal_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("cabal"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/clang_format.rs b/src/formatters/clang_format.rs index 6703855f..f72f341d 100644 --- a/src/formatters/clang_format.rs +++ b/src/formatters/clang_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_clang_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("clang-format"); cmd.arg("-i").arg(snippet_path); diff --git a/src/formatters/cljstyle.rs b/src/formatters/cljstyle.rs index f96a6e92..d3316b35 100644 --- a/src/formatters/cljstyle.rs +++ b/src/formatters/cljstyle.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_cljstyle( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("cljstyle"); cmd.arg("fix").arg(snippet_path); diff --git a/src/formatters/crystal_format.rs b/src/formatters/crystal_format.rs index cd276a47..d2c5d54c 100644 --- a/src/formatters/crystal_format.rs +++ b/src/formatters/crystal_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_crystal_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("crystal"); cmd.arg("tool").arg("format").arg(snippet_path); diff --git a/src/formatters/csharpier.rs b/src/formatters/csharpier.rs index d4b8c869..09d42165 100644 --- a/src/formatters/csharpier.rs +++ b/src/formatters/csharpier.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_csharpier( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("dotnet"); cmd.arg("csharpier").arg(snippet_path); diff --git a/src/formatters/dart_format.rs b/src/formatters/dart_format.rs index 54ef2324..43468305 100644 --- a/src/formatters/dart_format.rs +++ b/src/formatters/dart_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_dart_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("dart"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/deno_fmt.rs b/src/formatters/deno_fmt.rs index b3f9f71a..f312cc48 100644 --- a/src/formatters/deno_fmt.rs +++ b/src/formatters/deno_fmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_deno_fmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("deno"); cmd.arg("fmt").arg("--quiet").arg(snippet_path); diff --git a/src/formatters/efmt.rs b/src/formatters/efmt.rs index d7dc109b..7ab60b2c 100644 --- a/src/formatters/efmt.rs +++ b/src/formatters/efmt.rs @@ -1,7 +1,8 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] -pub fn format_using_efmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option)> { +pub fn format_using_efmt(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("efmt"); cmd.arg("-w").arg(file_path); diff --git a/src/formatters/elm_format.rs b/src/formatters/elm_format.rs index fd4f837b..c82df0da 100644 --- a/src/formatters/elm_format.rs +++ b/src/formatters/elm_format.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_elm_format_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -10,7 +10,7 @@ fn set_elm_format_args(cmd: &mut std::process::Command, snippet_path: &std::path fn invoke_elm_format( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_elm_format_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -19,7 +19,7 @@ fn invoke_elm_format( #[inline] pub fn format_using_elm_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { invoke_elm_format(setup_npm_script("elm-format"), snippet_path) } diff --git a/src/formatters/erlfmt.rs b/src/formatters/erlfmt.rs index 8c4a1c8c..7989a359 100644 --- a/src/formatters/erlfmt.rs +++ b/src/formatters/erlfmt.rs @@ -1,7 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] -pub fn format_using_erlfmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option)> { +pub fn format_using_erlfmt( + file_path: &std::path::Path, +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("erlfmt"); cmd.arg("-w") diff --git a/src/formatters/fantomas.rs b/src/formatters/fantomas.rs index e9c4b56e..75846582 100644 --- a/src/formatters/fantomas.rs +++ b/src/formatters/fantomas.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_fantomas( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("fantomas"); cmd.arg(snippet_path); diff --git a/src/formatters/fourmolu.rs b/src/formatters/fourmolu.rs index 094da8ea..123fd2af 100644 --- a/src/formatters/fourmolu.rs +++ b/src/formatters/fourmolu.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_fourmolu( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("fourmolu"); cmd.arg("-i").arg(snippet_path); diff --git a/src/formatters/gleam_format.rs b/src/formatters/gleam_format.rs index a3940456..14618d72 100644 --- a/src/formatters/gleam_format.rs +++ b/src/formatters/gleam_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_gleam_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("gleam"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/gofmt.rs b/src/formatters/gofmt.rs index 611063f9..78acbd08 100644 --- a/src/formatters/gofmt.rs +++ b/src/formatters/gofmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_gofmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("gofmt"); cmd.arg("-w").arg(snippet_path); diff --git a/src/formatters/gofumpt.rs b/src/formatters/gofumpt.rs index 0df5cb2c..2c0a9464 100644 --- a/src/formatters/gofumpt.rs +++ b/src/formatters/gofumpt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_gofumpt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("gofumpt"); cmd.arg("-w").arg(snippet_path); diff --git a/src/formatters/goimports.rs b/src/formatters/goimports.rs index 1f63fe10..e9587d7c 100644 --- a/src/formatters/goimports.rs +++ b/src/formatters/goimports.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_goimports( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("goimports"); cmd.arg("-w").arg(snippet_path); diff --git a/src/formatters/google_java_format.rs b/src/formatters/google_java_format.rs index e1e44842..32ce27d0 100644 --- a/src/formatters/google_java_format.rs +++ b/src/formatters/google_java_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_google_java_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("google-java-format"); cmd.arg("-i").arg(snippet_path); diff --git a/src/formatters/hindent.rs b/src/formatters/hindent.rs index ce734a25..c486c764 100644 --- a/src/formatters/hindent.rs +++ b/src/formatters/hindent.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_hindent( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("hindent"); cmd.arg(snippet_path); diff --git a/src/formatters/isort.rs b/src/formatters/isort.rs index 4c179042..af975c20 100644 --- a/src/formatters/isort.rs +++ b/src/formatters/isort.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_isort( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("isort"); cmd.arg("--quiet").arg(snippet_path); diff --git a/src/formatters/juliaformatter_jl.rs b/src/formatters/juliaformatter_jl.rs index fb6cd6a4..b73cb7d5 100644 --- a/src/formatters/juliaformatter_jl.rs +++ b/src/formatters/juliaformatter_jl.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_juliaformatter_jl( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("julia"); cmd.arg("-E").arg(format!( diff --git a/src/formatters/just_fmt.rs b/src/formatters/just_fmt.rs index dba2a99b..058407c8 100644 --- a/src/formatters/just_fmt.rs +++ b/src/formatters/just_fmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_just_fmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("just"); cmd.arg("--fmt") diff --git a/src/formatters/ktfmt.rs b/src/formatters/ktfmt.rs index 5286cf58..01512b72 100644 --- a/src/formatters/ktfmt.rs +++ b/src/formatters/ktfmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_ktfmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("ktfmt"); cmd.arg("--format") diff --git a/src/formatters/ktlint.rs b/src/formatters/ktlint.rs index fc55b5c7..f27fedbd 100644 --- a/src/formatters/ktlint.rs +++ b/src/formatters/ktlint.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_ktlint( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("ktlint"); cmd.arg("--format") diff --git a/src/formatters/luaformatter.rs b/src/formatters/luaformatter.rs index 13779197..4963a069 100644 --- a/src/formatters/luaformatter.rs +++ b/src/formatters/luaformatter.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_luaformatter( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("lua-format"); cmd.arg("-i").arg(snippet_path); diff --git a/src/formatters/mix_format.rs b/src/formatters/mix_format.rs index 51db9472..2d27b3b8 100644 --- a/src/formatters/mix_format.rs +++ b/src/formatters/mix_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_mix_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("mix"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/mod.rs b/src/formatters/mod.rs index 7924ab57..3ba82e78 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -5,7 +5,8 @@ use tempfile::NamedTempFile; use which::which; use crate::{ - config::MdsfConfig, languages::Language, terminal::print_binary_not_in_path, LineInfo, DEBUG, + config::MdsfConfig, error::MdsfError, languages::Language, terminal::print_binary_not_in_path, + LineInfo, DEBUG, }; pub mod alejandra; @@ -115,20 +116,22 @@ pub fn read_snippet(file_path: &std::path::Path) -> std::io::Result { fn handle_post_execution( result: std::io::Result, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { - if let Err(err) = result { - if err.kind() == std::io::ErrorKind::NotFound { - return Ok((true, None)); +) -> Result<(bool, Option), MdsfError> { + match result { + Ok(true) => read_snippet(snippet_path) + .map(|code| (false, Some(code))) + .map_err(MdsfError::from), + + Ok(false) => Err(MdsfError::FormatterError), + + Err(err) => { + if err.kind() == std::io::ErrorKind::NotFound { + Ok((true, None)) + } else { + Err(MdsfError::from(err)) + } } - - return Err(err); - } - - if matches!(result, Ok(true)) { - return read_snippet(snippet_path).map(|code| (false, Some(code))); } - - Ok((false, None)) } fn spawn_command(cmd: &mut Command) -> std::io::Result { @@ -144,7 +147,7 @@ fn spawn_command(cmd: &mut Command) -> std::io::Result { pub fn execute_command( cmd: &mut Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { if !binary_in_path(cmd.get_program()) { return Ok((true, None)); } diff --git a/src/formatters/nimpretty.rs b/src/formatters/nimpretty.rs index 8d4016a4..8b50929e 100644 --- a/src/formatters/nimpretty.rs +++ b/src/formatters/nimpretty.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_nimpretty( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("nimpretty"); cmd.arg(snippet_path); diff --git a/src/formatters/nixfmt.rs b/src/formatters/nixfmt.rs index 57e93741..b4f287e6 100644 --- a/src/formatters/nixfmt.rs +++ b/src/formatters/nixfmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_nixfmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("nixfmt"); cmd.arg(snippet_path); diff --git a/src/formatters/nixpkgs_fmt.rs b/src/formatters/nixpkgs_fmt.rs index 8748042c..1802cde4 100644 --- a/src/formatters/nixpkgs_fmt.rs +++ b/src/formatters/nixpkgs_fmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_nixpkgs_fmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("nixpkgs-fmt"); cmd.arg(snippet_path); diff --git a/src/formatters/npm_groovy_lint.rs b/src/formatters/npm_groovy_lint.rs index 87145438..01727a16 100644 --- a/src/formatters/npm_groovy_lint.rs +++ b/src/formatters/npm_groovy_lint.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_npm_groovy_lint_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -11,7 +11,7 @@ fn set_npm_groovy_lint_args(cmd: &mut std::process::Command, snippet_path: &std: fn invoke_npm_groovy_lint( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_npm_groovy_lint_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -20,7 +20,7 @@ fn invoke_npm_groovy_lint( #[inline] pub fn format_using_npm_groovy_lint( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let path_result = invoke_npm_groovy_lint(std::process::Command::new("npm-groovy-lint"), snippet_path)?; diff --git a/src/formatters/ocamlformat.rs b/src/formatters/ocamlformat.rs index b9b04805..03a8dd94 100644 --- a/src/formatters/ocamlformat.rs +++ b/src/formatters/ocamlformat.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_ocamlformat( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("ocamlformat"); cmd.arg("--ignore-invalid-option") diff --git a/src/formatters/ocp_indent.rs b/src/formatters/ocp_indent.rs index 37c8b20b..2079d03b 100644 --- a/src/formatters/ocp_indent.rs +++ b/src/formatters/ocp_indent.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_ocp_indent( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("ocp-indent"); cmd.arg("--inplace").arg(snippet_path); diff --git a/src/formatters/ormolu.rs b/src/formatters/ormolu.rs index 6983ef7f..ba6ef420 100644 --- a/src/formatters/ormolu.rs +++ b/src/formatters/ormolu.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_ormolu( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("ormolu"); cmd.arg("--mode").arg("inplace").arg(snippet_path); diff --git a/src/formatters/perltidy.rs b/src/formatters/perltidy.rs index 319115bd..a6c65357 100644 --- a/src/formatters/perltidy.rs +++ b/src/formatters/perltidy.rs @@ -1,4 +1,5 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] fn set_perltidy_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -10,7 +11,7 @@ fn set_perltidy_args(cmd: &mut std::process::Command, snippet_path: &std::path:: fn invoke_perltidy( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_perltidy_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -19,7 +20,7 @@ fn invoke_perltidy( #[inline] pub fn format_using_perltidy( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { invoke_perltidy(std::process::Command::new("perltidy"), snippet_path) } diff --git a/src/formatters/prettier.rs b/src/formatters/prettier.rs index 4b0bded7..cb107fbc 100644 --- a/src/formatters/prettier.rs +++ b/src/formatters/prettier.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_prettier_args( @@ -11,7 +11,10 @@ fn set_prettier_args( cmd.arg("--embedded-language-formatting").arg("off"); } - cmd.arg("--write").arg(snippet_path); + cmd.arg("--log-level") + .arg("error") + .arg("--write") + .arg(snippet_path); } #[inline] @@ -19,7 +22,7 @@ fn invoke_prettier( mut cmd: std::process::Command, snippet_path: &std::path::Path, embedded_language_formatting: bool, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_prettier_args(&mut cmd, snippet_path, embedded_language_formatting); execute_command(&mut cmd, snippet_path) @@ -29,7 +32,7 @@ fn invoke_prettier( pub fn format_using_prettier( snippet_path: &std::path::Path, embedded_language_formatting: bool, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let global_result = invoke_prettier( std::process::Command::new("prettier"), snippet_path, diff --git a/src/formatters/purs_tidy.rs b/src/formatters/purs_tidy.rs index c64354b3..952d120a 100644 --- a/src/formatters/purs_tidy.rs +++ b/src/formatters/purs_tidy.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_purs_tidy_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -10,7 +10,7 @@ fn set_purs_tidy_args(cmd: &mut std::process::Command, snippet_path: &std::path: fn invoke_purs_tidy( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_purs_tidy_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -19,7 +19,7 @@ fn invoke_purs_tidy( #[inline] pub fn format_using_purs_tidy( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { invoke_purs_tidy(setup_npm_script("purs-tidy"), snippet_path) } diff --git a/src/formatters/rescript_format.rs b/src/formatters/rescript_format.rs index 5dab16c2..c36ce35f 100644 --- a/src/formatters/rescript_format.rs +++ b/src/formatters/rescript_format.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_rescript_format_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -10,7 +10,7 @@ fn set_rescript_format_args(cmd: &mut std::process::Command, snippet_path: &std: fn invote_rescript_format( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_rescript_format_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -19,7 +19,7 @@ fn invote_rescript_format( #[inline] pub fn format_using_rescript_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { invote_rescript_format(setup_npm_script("rescript"), snippet_path) } diff --git a/src/formatters/roc_format.rs b/src/formatters/roc_format.rs index d9d47421..5062d65b 100644 --- a/src/formatters/roc_format.rs +++ b/src/formatters/roc_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_roc_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("roc"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/rubocop.rs b/src/formatters/rubocop.rs index a8b03fd0..efd7fcd3 100644 --- a/src/formatters/rubocop.rs +++ b/src/formatters/rubocop.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_rubocop( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("rubocop"); cmd.arg("--fix-layout") diff --git a/src/formatters/rubyfmt.rs b/src/formatters/rubyfmt.rs index d4ce114b..7c7e167b 100644 --- a/src/formatters/rubyfmt.rs +++ b/src/formatters/rubyfmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_rubyfmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("rubyfmt"); cmd.arg("-i").arg(snippet_path); diff --git a/src/formatters/ruff.rs b/src/formatters/ruff.rs index 171fee4b..a241445a 100644 --- a/src/formatters/ruff.rs +++ b/src/formatters/ruff.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_ruff( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("ruff"); cmd.arg("format"); diff --git a/src/formatters/rufo.rs b/src/formatters/rufo.rs index 5679e101..6b6ddf59 100644 --- a/src/formatters/rufo.rs +++ b/src/formatters/rufo.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_rufo( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("rufo"); cmd.arg("--simple-exit").arg(snippet_path); diff --git a/src/formatters/rustfmt.rs b/src/formatters/rustfmt.rs index f8967609..3673afaf 100644 --- a/src/formatters/rustfmt.rs +++ b/src/formatters/rustfmt.rs @@ -1,15 +1,16 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_rustfmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("rustfmt"); // Needed for async cmd.arg("--edition").arg("2021"); - cmd.arg(snippet_path); + cmd.arg("--quiet").arg(snippet_path); execute_command(&mut cmd, snippet_path) } diff --git a/src/formatters/scalafmt.rs b/src/formatters/scalafmt.rs index 1a69ae6b..fc5d8411 100644 --- a/src/formatters/scalafmt.rs +++ b/src/formatters/scalafmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_scalafmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("scalafmt"); #[cfg(test)] diff --git a/src/formatters/shfmt.rs b/src/formatters/shfmt.rs index c0abc824..8db9c83d 100644 --- a/src/formatters/shfmt.rs +++ b/src/formatters/shfmt.rs @@ -1,7 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] -pub fn format_using_shfmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option)> { +pub fn format_using_shfmt( + file_path: &std::path::Path, +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("shfmt"); cmd.arg("--write").arg(file_path); diff --git a/src/formatters/sql_formatter.rs b/src/formatters/sql_formatter.rs index a7eb7351..ebc36993 100644 --- a/src/formatters/sql_formatter.rs +++ b/src/formatters/sql_formatter.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_sql_formatter_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -10,7 +10,7 @@ fn set_sql_formatter_args(cmd: &mut std::process::Command, snippet_path: &std::p fn invote_sql_formatter( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_sql_formatter_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -19,7 +19,7 @@ fn invote_sql_formatter( #[inline] pub fn format_using_sql_formatter( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { invote_sql_formatter(setup_npm_script("sql-formatter"), snippet_path) } diff --git a/src/formatters/sqlfluff.rs b/src/formatters/sqlfluff.rs index 6ef845d8..6b1967f8 100644 --- a/src/formatters/sqlfluff.rs +++ b/src/formatters/sqlfluff.rs @@ -1,4 +1,5 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] fn set_sqlfluff_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -13,7 +14,7 @@ fn set_sqlfluff_args(cmd: &mut std::process::Command, snippet_path: &std::path:: fn invote_sqlfluff( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_sqlfluff_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -22,7 +23,7 @@ fn invote_sqlfluff( #[inline] pub fn format_using_sqlfluff( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { invote_sqlfluff(std::process::Command::new("sqlfluff"), snippet_path) } diff --git a/src/formatters/standardjs.rs b/src/formatters/standardjs.rs index a3b1195c..b81b82d1 100644 --- a/src/formatters/standardjs.rs +++ b/src/formatters/standardjs.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_standardjs_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -10,7 +10,7 @@ fn set_standardjs_args(cmd: &mut std::process::Command, snippet_path: &std::path fn invoke_standardjs( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_standardjs_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -19,7 +19,7 @@ fn invoke_standardjs( #[inline] pub fn format_using_standardjs( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let global_result = invoke_standardjs(std::process::Command::new("standard"), snippet_path)?; if !global_result.0 { diff --git a/src/formatters/standardrb.rs b/src/formatters/standardrb.rs index 2c28ee20..657472ab 100644 --- a/src/formatters/standardrb.rs +++ b/src/formatters/standardrb.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_standardrb( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("standardrb"); cmd.arg("--fix").arg(snippet_path); diff --git a/src/formatters/stylelint.rs b/src/formatters/stylelint.rs index a5862e87..d89075be 100644 --- a/src/formatters/stylelint.rs +++ b/src/formatters/stylelint.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_stylelint_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -10,7 +10,7 @@ fn set_stylelint_args(cmd: &mut std::process::Command, snippet_path: &std::path: fn invoke_stylelint( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_stylelint_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -19,7 +19,7 @@ fn invoke_stylelint( #[inline] pub fn format_using_stylelint( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let global_result = invoke_stylelint(std::process::Command::new("stylelint"), snippet_path)?; if !global_result.0 { diff --git a/src/formatters/stylish_haskell.rs b/src/formatters/stylish_haskell.rs index 9846bef5..18e1189d 100644 --- a/src/formatters/stylish_haskell.rs +++ b/src/formatters/stylish_haskell.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_stylish_haskell( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("stylish-haskell"); cmd.arg("--inplace").arg(snippet_path); diff --git a/src/formatters/stylua.rs b/src/formatters/stylua.rs index 9b9b3706..f5c78d64 100644 --- a/src/formatters/stylua.rs +++ b/src/formatters/stylua.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_stylua_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -11,7 +11,7 @@ fn set_stylua_args(cmd: &mut std::process::Command, snippet_path: &std::path::Pa fn invoke_stylua( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_stylua_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -20,7 +20,7 @@ fn invoke_stylua( #[inline] pub fn format_using_stylua( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let path_result = invoke_stylua(std::process::Command::new("stylua"), snippet_path)?; if !path_result.0 { diff --git a/src/formatters/swift_format.rs b/src/formatters/swift_format.rs index 519df589..e8d8ccd9 100644 --- a/src/formatters/swift_format.rs +++ b/src/formatters/swift_format.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_swift_format( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("swift-format"); cmd.arg("--in-place").arg(snippet_path); diff --git a/src/formatters/swiftformat.rs b/src/formatters/swiftformat.rs index e409b7d5..dbba6229 100644 --- a/src/formatters/swiftformat.rs +++ b/src/formatters/swiftformat.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_swiftformat( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("swiftformat"); cmd.arg("--quiet").arg(snippet_path); diff --git a/src/formatters/taplo.rs b/src/formatters/taplo.rs index 58887633..fbbea1d2 100644 --- a/src/formatters/taplo.rs +++ b/src/formatters/taplo.rs @@ -1,5 +1,5 @@ use super::execute_command; -use crate::runners::setup_npm_script; +use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] fn set_taplo_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { @@ -11,7 +11,7 @@ fn set_taplo_args(cmd: &mut std::process::Command, snippet_path: &std::path::Pat fn invoke_taplo( mut cmd: std::process::Command, snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { set_taplo_args(&mut cmd, snippet_path); execute_command(&mut cmd, snippet_path) @@ -20,7 +20,7 @@ fn invoke_taplo( #[inline] pub fn format_using_taplo( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let path_result = invoke_taplo(std::process::Command::new("taplo"), snippet_path)?; if !path_result.0 { diff --git a/src/formatters/terraform_fmt.rs b/src/formatters/terraform_fmt.rs index b807cb33..16794010 100644 --- a/src/formatters/terraform_fmt.rs +++ b/src/formatters/terraform_fmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_terraform_fmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("terraform"); cmd.arg("fmt").arg("-write=true").arg(snippet_path); diff --git a/src/formatters/tofu_fmt.rs b/src/formatters/tofu_fmt.rs index f1a1ba56..bd077da4 100644 --- a/src/formatters/tofu_fmt.rs +++ b/src/formatters/tofu_fmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_tofu_fmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("tofu"); cmd.arg("fmt").arg("-write=true").arg(snippet_path); diff --git a/src/formatters/usort.rs b/src/formatters/usort.rs index e79b79ea..abaecc57 100644 --- a/src/formatters/usort.rs +++ b/src/formatters/usort.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_usort( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("usort"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/xmlformat.rs b/src/formatters/xmlformat.rs index d5b9bb5c..9a85b94a 100644 --- a/src/formatters/xmlformat.rs +++ b/src/formatters/xmlformat.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_xmlformat( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("xmlformat"); cmd.arg("--overwrite").arg(snippet_path); diff --git a/src/formatters/xmllint.rs b/src/formatters/xmllint.rs index 0ff006a3..8469f49f 100644 --- a/src/formatters/xmllint.rs +++ b/src/formatters/xmllint.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_xmllint( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("xmllint"); cmd.arg("--format") diff --git a/src/formatters/yamlfix.rs b/src/formatters/yamlfix.rs index 36538a89..c1d4439c 100644 --- a/src/formatters/yamlfix.rs +++ b/src/formatters/yamlfix.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_yamlfix( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("yamlfix"); cmd.arg(snippet_path); diff --git a/src/formatters/yamlfmt.rs b/src/formatters/yamlfmt.rs index f762d4f2..997c7c3f 100644 --- a/src/formatters/yamlfmt.rs +++ b/src/formatters/yamlfmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_yamlfmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("yamlfmt"); cmd.arg("-quiet").arg(snippet_path); diff --git a/src/formatters/yapf.rs b/src/formatters/yapf.rs index 93846d9d..1d299b68 100644 --- a/src/formatters/yapf.rs +++ b/src/formatters/yapf.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_yapf( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("yapf"); cmd.arg("--in-place").arg(snippet_path); diff --git a/src/formatters/zigfmt.rs b/src/formatters/zigfmt.rs index cd493a41..cd28e0aa 100644 --- a/src/formatters/zigfmt.rs +++ b/src/formatters/zigfmt.rs @@ -1,9 +1,10 @@ use super::execute_command; +use crate::error::MdsfError; #[inline] pub fn format_using_zigfmt( snippet_path: &std::path::Path, -) -> std::io::Result<(bool, Option)> { +) -> Result<(bool, Option), MdsfError> { let mut cmd = std::process::Command::new("zig"); cmd.arg("fmt"); diff --git a/src/languages/blade.rs b/src/languages/blade.rs index a2125eff..fc73e4dd 100644 --- a/src/languages/blade.rs +++ b/src/languages/blade.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{blade_formatter::format_using_blade_formatter, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{blade_formatter::format_using_blade_formatter, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Blade { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::BladeFormatter => format_using_blade_formatter(snippet_path), } diff --git a/src/languages/c.rs b/src/languages/c.rs index 0a862582..0aebc96f 100644 --- a/src/languages/c.rs +++ b/src/languages/c.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{clang_format::format_using_clang_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{clang_format::format_using_clang_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for C { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::ClangFormat => format_using_clang_format(snippet_path), } diff --git a/src/languages/cabal.rs b/src/languages/cabal.rs index 023474ad..0980fe85 100644 --- a/src/languages/cabal.rs +++ b/src/languages/cabal.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{cabal_format::format_using_cabal_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{cabal_format::format_using_cabal_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Cabal { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::CabalFormat => format_using_cabal_format(snippet_path), } diff --git a/src/languages/clojure.rs b/src/languages/clojure.rs index 689e0ccd..3867c450 100644 --- a/src/languages/clojure.rs +++ b/src/languages/clojure.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{cljstyle::format_using_cljstyle, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{cljstyle::format_using_cljstyle, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Clojure { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Cljstyle => format_using_cljstyle(snippet_path), } diff --git a/src/languages/cpp.rs b/src/languages/cpp.rs index a53e7c83..01b6d4cc 100644 --- a/src/languages/cpp.rs +++ b/src/languages/cpp.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{clang_format::format_using_clang_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{clang_format::format_using_clang_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Cpp { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::ClangFormat => format_using_clang_format(snippet_path), } diff --git a/src/languages/crystal.rs b/src/languages/crystal.rs index c67794df..431535bb 100644 --- a/src/languages/crystal.rs +++ b/src/languages/crystal.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{crystal_format::format_using_crystal_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{crystal_format::format_using_crystal_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Crystal { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::CrystalFormat => format_using_crystal_format(snippet_path), } diff --git a/src/languages/csharp.rs b/src/languages/csharp.rs index fe855354..c99f4e6a 100644 --- a/src/languages/csharp.rs +++ b/src/languages/csharp.rs @@ -1,8 +1,11 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - clang_format::format_using_clang_format, csharpier::format_using_csharpier, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + clang_format::format_using_clang_format, csharpier::format_using_csharpier, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -40,7 +43,7 @@ impl LanguageFormatter for CSharp { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::CSharpier => format_using_csharpier(snippet_path), Self::ClangFormat => format_using_clang_format(snippet_path), diff --git a/src/languages/css.rs b/src/languages/css.rs index 61fddb87..721249a3 100644 --- a/src/languages/css.rs +++ b/src/languages/css.rs @@ -1,8 +1,11 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - prettier::format_using_prettier, stylelint::format_using_stylelint, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + prettier::format_using_prettier, stylelint::format_using_stylelint, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -37,7 +40,7 @@ impl LanguageFormatter for Css { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Prettier => format_using_prettier(snippet_path, true), Self::StyleLint => format_using_stylelint(snippet_path), diff --git a/src/languages/dart.rs b/src/languages/dart.rs index f72221af..a9efedc9 100644 --- a/src/languages/dart.rs +++ b/src/languages/dart.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{dart_format::format_using_dart_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{dart_format::format_using_dart_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Dart { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::DartFormat => format_using_dart_format(snippet_path), } diff --git a/src/languages/elixir.rs b/src/languages/elixir.rs index 0acff09e..633e71ef 100644 --- a/src/languages/elixir.rs +++ b/src/languages/elixir.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{mix_format::format_using_mix_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{mix_format::format_using_mix_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Elixir { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::MixFormat => format_using_mix_format(snippet_path), } diff --git a/src/languages/elm.rs b/src/languages/elm.rs index f97a9575..4f9e2745 100644 --- a/src/languages/elm.rs +++ b/src/languages/elm.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{elm_format::format_using_elm_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{elm_format::format_using_elm_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Elm { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::ElmFormat => format_using_elm_format(snippet_path), } diff --git a/src/languages/erlang.rs b/src/languages/erlang.rs index d8dced5c..9200d0fd 100644 --- a/src/languages/erlang.rs +++ b/src/languages/erlang.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{efmt::format_using_efmt, erlfmt::format_using_erlfmt, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{efmt::format_using_efmt, erlfmt::format_using_erlfmt, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -35,7 +38,7 @@ impl LanguageFormatter for Erlang { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Erlfmt => format_using_erlfmt(snippet_path), Self::Efmt => format_using_efmt(snippet_path), diff --git a/src/languages/fsharp.rs b/src/languages/fsharp.rs index 5590d1b7..0b0ecb98 100644 --- a/src/languages/fsharp.rs +++ b/src/languages/fsharp.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{fantomas::format_using_fantomas, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{fantomas::format_using_fantomas, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for FSharp { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Fantomas => format_using_fantomas(snippet_path), } diff --git a/src/languages/gleam.rs b/src/languages/gleam.rs index 3a8f5c00..364423db 100644 --- a/src/languages/gleam.rs +++ b/src/languages/gleam.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{gleam_format::format_using_gleam_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{gleam_format::format_using_gleam_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Gleam { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::GleamFormat => format_using_gleam_format(snippet_path), } diff --git a/src/languages/go.rs b/src/languages/go.rs index 9935dfff..2218c8bc 100644 --- a/src/languages/go.rs +++ b/src/languages/go.rs @@ -1,9 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - gofmt::format_using_gofmt, gofumpt::format_using_gofumpt, goimports::format_using_goimports, - MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + gofmt::format_using_gofmt, gofumpt::format_using_gofumpt, + goimports::format_using_goimports, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -43,7 +46,7 @@ impl LanguageFormatter for Go { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::GoFmt => format_using_gofmt(snippet_path), Self::GoFumpt => format_using_gofumpt(snippet_path), diff --git a/src/languages/graphql.rs b/src/languages/graphql.rs index f0b7cb41..1ca2b1af 100644 --- a/src/languages/graphql.rs +++ b/src/languages/graphql.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{prettier::format_using_prettier, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{prettier::format_using_prettier, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for GraphQL { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Prettier => format_using_prettier(snippet_path, true), } diff --git a/src/languages/groovy.rs b/src/languages/groovy.rs index 72c7b684..c9fb9280 100644 --- a/src/languages/groovy.rs +++ b/src/languages/groovy.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{npm_groovy_lint::format_using_npm_groovy_lint, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{npm_groovy_lint::format_using_npm_groovy_lint, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Groovy { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::NpmGroovyLint => format_using_npm_groovy_lint(snippet_path), } diff --git a/src/languages/haskell.rs b/src/languages/haskell.rs index 51f1af5a..517c8766 100644 --- a/src/languages/haskell.rs +++ b/src/languages/haskell.rs @@ -1,9 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - fourmolu::format_using_fourmolu, hindent::format_using_hindent, ormolu::format_using_ormolu, - stylish_haskell::format_using_stylish_haskell, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + fourmolu::format_using_fourmolu, hindent::format_using_hindent, + ormolu::format_using_ormolu, stylish_haskell::format_using_stylish_haskell, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -46,7 +49,7 @@ impl LanguageFormatter for Haskell { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Fourmolu => format_using_fourmolu(snippet_path), Self::Ormolu => format_using_ormolu(snippet_path), diff --git a/src/languages/hcl.rs b/src/languages/hcl.rs index f4cdbbb2..32618e9b 100644 --- a/src/languages/hcl.rs +++ b/src/languages/hcl.rs @@ -1,8 +1,11 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - terraform_fmt::format_using_terraform_fmt, tofu_fmt::format_using_tofu_fmt, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + terraform_fmt::format_using_terraform_fmt, tofu_fmt::format_using_tofu_fmt, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -40,7 +43,7 @@ impl LanguageFormatter for Hcl { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::TerraformFmt => format_using_terraform_fmt(snippet_path), Self::TofuFmt => format_using_tofu_fmt(snippet_path), diff --git a/src/languages/html.rs b/src/languages/html.rs index 08f8452a..581cff77 100644 --- a/src/languages/html.rs +++ b/src/languages/html.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{prettier::format_using_prettier, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{prettier::format_using_prettier, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Html { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Prettier => format_using_prettier(snippet_path, true), } diff --git a/src/languages/java.rs b/src/languages/java.rs index 5423d118..a189c882 100644 --- a/src/languages/java.rs +++ b/src/languages/java.rs @@ -1,9 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - clang_format::format_using_clang_format, google_java_format::format_using_google_java_format, - MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + clang_format::format_using_clang_format, + google_java_format::format_using_google_java_format, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -41,7 +44,7 @@ impl LanguageFormatter for Java { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::ClangFormat => format_using_clang_format(snippet_path), Self::GoogleJavaFormat => format_using_google_java_format(snippet_path), diff --git a/src/languages/javascript.rs b/src/languages/javascript.rs index 4d11160b..b2e694a9 100644 --- a/src/languages/javascript.rs +++ b/src/languages/javascript.rs @@ -1,10 +1,13 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - biome::format_using_biome, clang_format::format_using_clang_format, - deno_fmt::format_using_deno_fmt, prettier::format_using_prettier, - standardjs::format_using_standardjs, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + biome::format_using_biome, clang_format::format_using_clang_format, + deno_fmt::format_using_deno_fmt, prettier::format_using_prettier, + standardjs::format_using_standardjs, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -50,7 +53,7 @@ impl LanguageFormatter for JavaScript { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Biome => format_using_biome(snippet_path), Self::Prettier => format_using_prettier(snippet_path, true), diff --git a/src/languages/json.rs b/src/languages/json.rs index c2abcb6c..9bcdd29c 100644 --- a/src/languages/json.rs +++ b/src/languages/json.rs @@ -1,9 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - biome::format_using_biome, clang_format::format_using_clang_format, - deno_fmt::format_using_deno_fmt, prettier::format_using_prettier, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + biome::format_using_biome, clang_format::format_using_clang_format, + deno_fmt::format_using_deno_fmt, prettier::format_using_prettier, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -47,7 +50,7 @@ impl LanguageFormatter for Json { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Biome => format_using_biome(snippet_path), Self::Prettier => format_using_prettier(snippet_path, true), diff --git a/src/languages/julia.rs b/src/languages/julia.rs index e9ddcd43..62a680b2 100644 --- a/src/languages/julia.rs +++ b/src/languages/julia.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{juliaformatter_jl::format_using_juliaformatter_jl, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{juliaformatter_jl::format_using_juliaformatter_jl, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Julia { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::JuliaFormatterJl => format_using_juliaformatter_jl(snippet_path), } diff --git a/src/languages/just.rs b/src/languages/just.rs index be6657cf..9a15104d 100644 --- a/src/languages/just.rs +++ b/src/languages/just.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{just_fmt::format_using_just_fmt, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{just_fmt::format_using_just_fmt, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Just { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::JustFmt => format_using_just_fmt(snippet_path), } diff --git a/src/languages/kotlin.rs b/src/languages/kotlin.rs index bdeca0fe..4eebdc6b 100644 --- a/src/languages/kotlin.rs +++ b/src/languages/kotlin.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ktfmt::format_using_ktfmt, ktlint::format_using_ktlint, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{ktfmt::format_using_ktfmt, ktlint::format_using_ktlint, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -38,7 +41,7 @@ impl LanguageFormatter for Kotlin { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Ktlint => format_using_ktlint(snippet_path), Self::Ktfmt => format_using_ktfmt(snippet_path), diff --git a/src/languages/lua.rs b/src/languages/lua.rs index abd981dd..ffadad34 100644 --- a/src/languages/lua.rs +++ b/src/languages/lua.rs @@ -1,8 +1,11 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - luaformatter::format_using_luaformatter, stylua::format_using_stylua, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + luaformatter::format_using_luaformatter, stylua::format_using_stylua, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -40,7 +43,7 @@ impl LanguageFormatter for Lua { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Stylua => format_using_stylua(snippet_path), Self::LuaFormatter => format_using_luaformatter(snippet_path), diff --git a/src/languages/markdown.rs b/src/languages/markdown.rs index 02d9586f..5cb4833f 100644 --- a/src/languages/markdown.rs +++ b/src/languages/markdown.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{prettier::format_using_prettier, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{prettier::format_using_prettier, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -42,7 +45,7 @@ impl LanguageFormatter for Markdown { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Prettier => format_using_prettier(snippet_path, false), } diff --git a/src/languages/mod.rs b/src/languages/mod.rs index db9b8440..c9b8ac55 100644 --- a/src/languages/mod.rs +++ b/src/languages/mod.rs @@ -1,6 +1,11 @@ use schemars::JsonSchema; -use crate::{formatters::MdsfFormatter, terminal::print_formatter_info, LineInfo}; +use crate::{ + error::MdsfError, + formatters::MdsfFormatter, + terminal::{print_error_formatting, print_formatter_info}, + LineInfo, +}; pub mod blade; pub mod c; @@ -262,7 +267,7 @@ pub trait LanguageFormatter { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)>; + ) -> Result<(bool, Option), MdsfError>; } impl Language { @@ -416,7 +421,7 @@ impl Lang { &self, snippet_path: &std::path::Path, info: &LineInfo, - ) -> std::io::Result> { + ) -> Result, MdsfError> { if !self.enabled { return Ok(None); } @@ -431,12 +436,20 @@ impl Lang { snippet_path: &std::path::Path, info: &LineInfo, nested: bool, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match formatter { MdsfFormatter::Single(f) => { - print_formatter_info(f.to_string().as_str(), info); + let formatter_name = f.to_string(); - f.format_snippet(snippet_path) + print_formatter_info(&formatter_name, info); + + let r = f.format_snippet(snippet_path); + + if r.is_err() { + print_error_formatting(&formatter_name, info); + } + + r } MdsfFormatter::Multiple(formatters) => { @@ -465,6 +478,7 @@ mod test_lang { use super::{Lang, LanguageFormatter}; use crate::{ + error::MdsfError, formatters::{setup_snippet, MdsfFormatter}, LineInfo, }; @@ -495,7 +509,7 @@ mod test_lang { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { let mut file = std::fs::OpenOptions::new() .append(true) .open(snippet_path)?; diff --git a/src/languages/nim.rs b/src/languages/nim.rs index 2a9158d2..67d8e655 100644 --- a/src/languages/nim.rs +++ b/src/languages/nim.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{nimpretty::format_using_nimpretty, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{nimpretty::format_using_nimpretty, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Nim { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Nimpretty => format_using_nimpretty(snippet_path), } diff --git a/src/languages/nix.rs b/src/languages/nix.rs index 281e2724..5b1a7549 100644 --- a/src/languages/nix.rs +++ b/src/languages/nix.rs @@ -1,9 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - alejandra::format_using_alejandra, nixfmt::format_using_nixfmt, - nixpkgs_fmt::format_using_nixpkgs_fmt, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + alejandra::format_using_alejandra, nixfmt::format_using_nixfmt, + nixpkgs_fmt::format_using_nixpkgs_fmt, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -44,7 +47,7 @@ impl LanguageFormatter for Nix { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Alejandra => format_using_alejandra(snippet_path), Self::Nixfmt => format_using_nixfmt(snippet_path), diff --git a/src/languages/objective_c.rs b/src/languages/objective_c.rs index 42eb62b6..ec0ccad1 100644 --- a/src/languages/objective_c.rs +++ b/src/languages/objective_c.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{clang_format::format_using_clang_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{clang_format::format_using_clang_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for ObjectiveC { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::ClangFormat => format_using_clang_format(snippet_path), } diff --git a/src/languages/ocaml.rs b/src/languages/ocaml.rs index 0c684a50..0db9fb26 100644 --- a/src/languages/ocaml.rs +++ b/src/languages/ocaml.rs @@ -1,8 +1,11 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - ocamlformat::format_using_ocamlformat, ocp_indent::format_using_ocp_indent, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + ocamlformat::format_using_ocamlformat, ocp_indent::format_using_ocp_indent, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -40,7 +43,7 @@ impl LanguageFormatter for OCaml { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::OCamlFormat => format_using_ocamlformat(snippet_path), Self::OcpIndent => format_using_ocp_indent(snippet_path), diff --git a/src/languages/perl.rs b/src/languages/perl.rs index 2bed64d5..988ad12e 100644 --- a/src/languages/perl.rs +++ b/src/languages/perl.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{perltidy::format_using_perltidy, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{perltidy::format_using_perltidy, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Perl { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::PerlTidy => format_using_perltidy(snippet_path), } diff --git a/src/languages/protobuf.rs b/src/languages/protobuf.rs index b7538d27..c431eca0 100644 --- a/src/languages/protobuf.rs +++ b/src/languages/protobuf.rs @@ -1,8 +1,9 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - buf::format_using_buf, clang_format::format_using_clang_format, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{buf::format_using_buf, clang_format::format_using_clang_format, MdsfFormatter}, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -40,7 +41,7 @@ impl LanguageFormatter for Protobuf { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Buf => format_using_buf(snippet_path), Self::ClangFormat => format_using_clang_format(snippet_path), diff --git a/src/languages/purescript.rs b/src/languages/purescript.rs index c30a3a07..65cebd0a 100644 --- a/src/languages/purescript.rs +++ b/src/languages/purescript.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{purs_tidy::format_using_purs_tidy, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{purs_tidy::format_using_purs_tidy, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for PureScript { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::PursTidy => format_using_purs_tidy(snippet_path), } diff --git a/src/languages/python.rs b/src/languages/python.rs index 8f8edfca..e81a7763 100644 --- a/src/languages/python.rs +++ b/src/languages/python.rs @@ -1,10 +1,13 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - autopep8::format_using_autopep8, black::format_using_black, blue::format_using_blue, - isort::format_using_isort, ruff::format_using_ruff, usort::format_using_usort, - yapf::format_using_yapf, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + autopep8::format_using_autopep8, black::format_using_black, blue::format_using_blue, + isort::format_using_isort, ruff::format_using_ruff, usort::format_using_usort, + yapf::format_using_yapf, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -32,7 +35,7 @@ impl LanguageFormatter for Python { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Autopep8 => format_using_autopep8(snippet_path), Self::Black => format_using_black(snippet_path), diff --git a/src/languages/rescript.rs b/src/languages/rescript.rs index 10045363..e3c60f8a 100644 --- a/src/languages/rescript.rs +++ b/src/languages/rescript.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{rescript_format::format_using_rescript_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{rescript_format::format_using_rescript_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for ReScript { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::ReScriptFormat => format_using_rescript_format(snippet_path), } diff --git a/src/languages/roc.rs b/src/languages/roc.rs index 694cf901..b2e17620 100644 --- a/src/languages/roc.rs +++ b/src/languages/roc.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{roc_format::format_using_roc_format, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{roc_format::format_using_roc_format, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Roc { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::RocFormat => format_using_roc_format(snippet_path), } diff --git a/src/languages/ruby.rs b/src/languages/ruby.rs index 6e85f876..7730903d 100644 --- a/src/languages/ruby.rs +++ b/src/languages/ruby.rs @@ -1,9 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - rubocop::format_using_rubocop, rubyfmt::format_using_rubyfmt, rufo::format_using_rufo, - standardrb::format_using_standardrb, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + rubocop::format_using_rubocop, rubyfmt::format_using_rubyfmt, rufo::format_using_rufo, + standardrb::format_using_standardrb, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -47,7 +50,7 @@ impl LanguageFormatter for Ruby { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::RuboCop => format_using_rubocop(snippet_path), Self::Rufo => format_using_rufo(snippet_path), diff --git a/src/languages/rust.rs b/src/languages/rust.rs index d21b1ec9..f51bccd1 100644 --- a/src/languages/rust.rs +++ b/src/languages/rust.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{rustfmt::format_using_rustfmt, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{rustfmt::format_using_rustfmt, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Rust { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::RustFmt => format_using_rustfmt(snippet_path), } diff --git a/src/languages/scala.rs b/src/languages/scala.rs index 73811cd1..c52913a9 100644 --- a/src/languages/scala.rs +++ b/src/languages/scala.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{scalafmt::format_using_scalafmt, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{scalafmt::format_using_scalafmt, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Scala { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Scalafmt => format_using_scalafmt(snippet_path), } diff --git a/src/languages/shell.rs b/src/languages/shell.rs index 5d3622d0..6c070c9d 100644 --- a/src/languages/shell.rs +++ b/src/languages/shell.rs @@ -1,8 +1,9 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - beautysh::format_using_beautysh, shfmt::format_using_shfmt, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{beautysh::format_using_beautysh, shfmt::format_using_shfmt, MdsfFormatter}, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -50,7 +51,7 @@ impl LanguageFormatter for Shell { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Shfmt => format_using_shfmt(snippet_path), Self::Beautysh => format_using_beautysh(snippet_path), diff --git a/src/languages/sql.rs b/src/languages/sql.rs index e70d788d..b80e28f0 100644 --- a/src/languages/sql.rs +++ b/src/languages/sql.rs @@ -1,8 +1,11 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - sql_formatter::format_using_sql_formatter, sqlfluff::format_using_sqlfluff, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + sql_formatter::format_using_sql_formatter, sqlfluff::format_using_sqlfluff, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -50,7 +53,7 @@ impl LanguageFormatter for Sql { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::SQLFormatter => format_using_sql_formatter(snippet_path), Self::Sqlfluff => format_using_sqlfluff(snippet_path), diff --git a/src/languages/swift.rs b/src/languages/swift.rs index db20405c..25fb680e 100644 --- a/src/languages/swift.rs +++ b/src/languages/swift.rs @@ -1,8 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - swift_format::format_using_swift_format, swiftformat::format_using_swiftformat, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + swift_format::format_using_swift_format, swiftformat::format_using_swiftformat, + MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -40,7 +44,7 @@ impl LanguageFormatter for Swift { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::AppleSwiftFormat => format_using_swift_format(snippet_path), Self::NicklockwoodSwiftFormat => format_using_swiftformat(snippet_path), diff --git a/src/languages/toml.rs b/src/languages/toml.rs index 86bafb37..aadcba62 100644 --- a/src/languages/toml.rs +++ b/src/languages/toml.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{taplo::format_using_taplo, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{taplo::format_using_taplo, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Toml { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Taplo => format_using_taplo(snippet_path), } diff --git a/src/languages/typescript.rs b/src/languages/typescript.rs index 3e3dd97c..4ccd28b4 100644 --- a/src/languages/typescript.rs +++ b/src/languages/typescript.rs @@ -1,9 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - biome::format_using_biome, deno_fmt::format_using_deno_fmt, prettier::format_using_prettier, - MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + biome::format_using_biome, deno_fmt::format_using_deno_fmt, + prettier::format_using_prettier, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -44,7 +47,7 @@ impl LanguageFormatter for TypeScript { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Biome => format_using_biome(snippet_path), Self::Prettier => format_using_prettier(snippet_path, true), diff --git a/src/languages/vue.rs b/src/languages/vue.rs index 8210b7a2..ed9a5068 100644 --- a/src/languages/vue.rs +++ b/src/languages/vue.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{prettier::format_using_prettier, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{prettier::format_using_prettier, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Vue { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Prettier => format_using_prettier(snippet_path, true), } diff --git a/src/languages/xml.rs b/src/languages/xml.rs index 3a6b8d37..32d3d006 100644 --- a/src/languages/xml.rs +++ b/src/languages/xml.rs @@ -1,8 +1,9 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - xmlformat::format_using_xmlformat, xmllint::format_using_xmllint, MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{xmlformat::format_using_xmlformat, xmllint::format_using_xmllint, MdsfFormatter}, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -40,7 +41,7 @@ impl LanguageFormatter for Xml { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::XmlLint => format_using_xmllint(snippet_path), Self::XmlFormat => format_using_xmlformat(snippet_path), diff --git a/src/languages/yaml.rs b/src/languages/yaml.rs index d91e3584..b6048fad 100644 --- a/src/languages/yaml.rs +++ b/src/languages/yaml.rs @@ -1,9 +1,12 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{ - prettier::format_using_prettier, yamlfix::format_using_yamlfix, yamlfmt::format_using_yamlfmt, - MdsfFormatter, +use crate::{ + error::MdsfError, + formatters::{ + prettier::format_using_prettier, yamlfix::format_using_yamlfix, + yamlfmt::format_using_yamlfmt, MdsfFormatter, + }, }; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] @@ -44,7 +47,7 @@ impl LanguageFormatter for Yaml { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::Prettier => format_using_prettier(snippet_path, true), Self::YamlFmt => format_using_yamlfmt(snippet_path), diff --git a/src/languages/zig.rs b/src/languages/zig.rs index fb90e3f7..02903f64 100644 --- a/src/languages/zig.rs +++ b/src/languages/zig.rs @@ -1,7 +1,10 @@ use schemars::JsonSchema; use super::{Lang, LanguageFormatter}; -use crate::formatters::{zigfmt::format_using_zigfmt, MdsfFormatter}; +use crate::{ + error::MdsfError, + formatters::{zigfmt::format_using_zigfmt, MdsfFormatter}, +}; #[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] @@ -33,7 +36,7 @@ impl LanguageFormatter for Zig { fn format_snippet( &self, snippet_path: &std::path::Path, - ) -> std::io::Result<(bool, Option)> { + ) -> Result<(bool, Option), MdsfError> { match self { Self::ZigFmt => format_using_zigfmt(snippet_path), } diff --git a/src/terminal/logging.rs b/src/terminal/logging.rs index 0301fc4d..fe565528 100644 --- a/src/terminal/logging.rs +++ b/src/terminal/logging.rs @@ -29,7 +29,9 @@ pub fn setup_logger(log_level: LogLevel) { .format_target(false) .format_level(false) .format(move |buf, record| match record.level() { - log::Level::Error => writeln!(buf, "{}", style(format!("{}", record.args())).red()), + log::Level::Error => { + writeln!(buf, "{}", style(format!("{}", record.args())).red().bold()) + } log::Level::Warn => writeln!( buf, "{}", diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index b2dc54fb..f40769f5 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -53,3 +53,11 @@ pub fn print_unknown_javascript_runtime(value: u8, fallback: JavaScriptRuntime) pub fn print_binary_not_in_path(binary_name: &str) { warn!("'{binary_name}' not found in path"); } + +#[inline] +pub fn print_error_formatting(formatter_name: &str, info: &LineInfo) { + error!( + "{} error formatting using {formatter_name}", + info.filename.display(), + ); +} From 4c5114bcc7374953edbd06d077cd670234db3cf8 Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Fri, 5 Apr 2024 18:00:04 +0200 Subject: [PATCH 2/2] refactor: propagate errors --- justfile | 1 + src/error.rs | 19 ++++++++++++------- src/formatters/mod.rs | 20 ++++++++------------ src/formatters/npm_groovy_lint.rs | 11 ++++++----- src/formatters/prettier.rs | 10 +++++----- src/formatters/scalafmt.rs | 1 - src/formatters/standardjs.rs | 9 +++++---- src/formatters/stylelint.rs | 9 +++++---- src/formatters/stylua.rs | 8 ++++---- src/formatters/taplo.rs | 8 ++++---- src/languages/mod.rs | 20 +++++++++++++++++--- src/terminal/mod.rs | 12 +++++++----- 12 files changed, 74 insertions(+), 54 deletions(-) diff --git a/justfile b/justfile index 93feff04..0685b502 100644 --- a/justfile +++ b/justfile @@ -44,6 +44,7 @@ precommit: just test just update-readme cargo run -- init + cargo run -- format . npx prettier --write mdsf.json typos . diff --git a/src/error.rs b/src/error.rs index ee77e2e7..2cd97374 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,9 +2,13 @@ pub enum MdsfError { Io(std::io::Error), Fmt(core::fmt::Error), + // TODO: use &std::path::Path ConfigParse(std::path::PathBuf), + // TODO: use &std::path::Path FileNotFound(std::path::PathBuf), FormatterError, + // TODO: use &str + MissingBinary(String), } impl core::fmt::Display for MdsfError { @@ -13,15 +17,16 @@ impl core::fmt::Display for MdsfError { match self { Self::Io(e) => e.fmt(f), Self::Fmt(e) => e.fmt(f), - Self::ConfigParse(path) => f.write_fmt(format_args!( - "Error parsing config found at '{}'", - path.display() - )), - Self::FileNotFound(path) => f.write_fmt(format_args!( + Self::ConfigParse(path) => { + write!(f, "Error parsing config found at '{}'", path.display()) + } + Self::FileNotFound(path) => write!( + f, "No file or directory with the name '{}' found", path.display() - )), - Self::FormatterError => f.write_str("Error formatting"), + ), + Self::FormatterError => write!(f, "Error formatting codeblock"), + Self::MissingBinary(binary_name) => write!(f, "{binary_name} was not found in path"), } } } diff --git a/src/formatters/mod.rs b/src/formatters/mod.rs index 3ba82e78..a8c997ae 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -4,10 +4,7 @@ use schemars::JsonSchema; use tempfile::NamedTempFile; use which::which; -use crate::{ - config::MdsfConfig, error::MdsfError, languages::Language, terminal::print_binary_not_in_path, - LineInfo, DEBUG, -}; +use crate::{config::MdsfConfig, error::MdsfError, languages::Language, LineInfo, DEBUG}; pub mod alejandra; pub mod autopep8; @@ -148,8 +145,12 @@ pub fn execute_command( cmd: &mut Command, snippet_path: &std::path::Path, ) -> Result<(bool, Option), MdsfError> { - if !binary_in_path(cmd.get_program()) { - return Ok((true, None)); + let binary_name = cmd.get_program(); + + if !binary_in_path(binary_name) { + return Err(MdsfError::MissingBinary( + binary_name.to_string_lossy().to_string(), + )); } handle_post_execution(spawn_command(cmd), snippet_path) @@ -236,10 +237,5 @@ where #[inline] pub fn binary_in_path(binary_name: &OsStr) -> bool { - if which(binary_name).is_ok() { - true - } else { - print_binary_not_in_path(&binary_name.to_string_lossy()); - false - } + which(binary_name).is_ok() } diff --git a/src/formatters/npm_groovy_lint.rs b/src/formatters/npm_groovy_lint.rs index 01727a16..f0837495 100644 --- a/src/formatters/npm_groovy_lint.rs +++ b/src/formatters/npm_groovy_lint.rs @@ -21,11 +21,12 @@ fn invoke_npm_groovy_lint( pub fn format_using_npm_groovy_lint( snippet_path: &std::path::Path, ) -> Result<(bool, Option), MdsfError> { - let path_result = - invoke_npm_groovy_lint(std::process::Command::new("npm-groovy-lint"), snippet_path)?; - - if !path_result.0 { - return Ok(path_result); + if let Ok(path_result) = + invoke_npm_groovy_lint(std::process::Command::new("npm-groovy-lint"), snippet_path) + { + if !path_result.0 { + return Ok(path_result); + } } invoke_npm_groovy_lint(setup_npm_script("npm-groovy-lint"), snippet_path) diff --git a/src/formatters/prettier.rs b/src/formatters/prettier.rs index cb107fbc..58ef6c79 100644 --- a/src/formatters/prettier.rs +++ b/src/formatters/prettier.rs @@ -33,14 +33,14 @@ pub fn format_using_prettier( snippet_path: &std::path::Path, embedded_language_formatting: bool, ) -> Result<(bool, Option), MdsfError> { - let global_result = invoke_prettier( + if let Ok(path_result) = invoke_prettier( std::process::Command::new("prettier"), snippet_path, embedded_language_formatting, - )?; - - if !global_result.0 { - return Ok(global_result); + ) { + if !path_result.0 { + return Ok(path_result); + } } invoke_prettier( diff --git a/src/formatters/scalafmt.rs b/src/formatters/scalafmt.rs index fc5d8411..46c2f952 100644 --- a/src/formatters/scalafmt.rs +++ b/src/formatters/scalafmt.rs @@ -10,7 +10,6 @@ pub fn format_using_scalafmt( #[cfg(test)] { cmd.arg("--config-str").arg("\"version=3.8.0\""); - cmd.arg("--debug"); }; diff --git a/src/formatters/standardjs.rs b/src/formatters/standardjs.rs index b81b82d1..22a3fc3d 100644 --- a/src/formatters/standardjs.rs +++ b/src/formatters/standardjs.rs @@ -20,10 +20,11 @@ fn invoke_standardjs( pub fn format_using_standardjs( snippet_path: &std::path::Path, ) -> Result<(bool, Option), MdsfError> { - let global_result = invoke_standardjs(std::process::Command::new("standard"), snippet_path)?; - - if !global_result.0 { - return Ok(global_result); + if let Ok(path_result) = invoke_standardjs(std::process::Command::new("standard"), snippet_path) + { + if !path_result.0 { + return Ok(path_result); + } } invoke_standardjs(setup_npm_script("standard"), snippet_path) diff --git a/src/formatters/stylelint.rs b/src/formatters/stylelint.rs index d89075be..3496dda2 100644 --- a/src/formatters/stylelint.rs +++ b/src/formatters/stylelint.rs @@ -20,10 +20,11 @@ fn invoke_stylelint( pub fn format_using_stylelint( snippet_path: &std::path::Path, ) -> Result<(bool, Option), MdsfError> { - let global_result = invoke_stylelint(std::process::Command::new("stylelint"), snippet_path)?; - - if !global_result.0 { - return Ok(global_result); + if let Ok(path_result) = invoke_stylelint(std::process::Command::new("stylelint"), snippet_path) + { + if !path_result.0 { + return Ok(path_result); + } } invoke_stylelint(setup_npm_script("stylelint"), snippet_path) diff --git a/src/formatters/stylua.rs b/src/formatters/stylua.rs index f5c78d64..90132221 100644 --- a/src/formatters/stylua.rs +++ b/src/formatters/stylua.rs @@ -21,10 +21,10 @@ fn invoke_stylua( pub fn format_using_stylua( snippet_path: &std::path::Path, ) -> Result<(bool, Option), MdsfError> { - let path_result = invoke_stylua(std::process::Command::new("stylua"), snippet_path)?; - - if !path_result.0 { - return Ok(path_result); + if let Ok(path_result) = invoke_stylua(std::process::Command::new("stylua"), snippet_path) { + if !path_result.0 { + return Ok(path_result); + } } invoke_stylua(setup_npm_script("@johnnymorganz/stylua-bin"), snippet_path) diff --git a/src/formatters/taplo.rs b/src/formatters/taplo.rs index fbbea1d2..a4fdc9e4 100644 --- a/src/formatters/taplo.rs +++ b/src/formatters/taplo.rs @@ -21,10 +21,10 @@ fn invoke_taplo( pub fn format_using_taplo( snippet_path: &std::path::Path, ) -> Result<(bool, Option), MdsfError> { - let path_result = invoke_taplo(std::process::Command::new("taplo"), snippet_path)?; - - if !path_result.0 { - return Ok(path_result); + if let Ok(path_result) = invoke_taplo(std::process::Command::new("taplo"), snippet_path) { + if !path_result.0 { + return Ok(path_result); + } } invoke_taplo(setup_npm_script("@taplo/cli"), snippet_path) diff --git a/src/languages/mod.rs b/src/languages/mod.rs index c9b8ac55..f8e31710 100644 --- a/src/languages/mod.rs +++ b/src/languages/mod.rs @@ -3,7 +3,7 @@ use schemars::JsonSchema; use crate::{ error::MdsfError, formatters::MdsfFormatter, - terminal::{print_error_formatting, print_formatter_info}, + terminal::{print_binary_not_in_path, print_error_formatting, print_formatter_info}, LineInfo, }; @@ -445,8 +445,22 @@ impl Lang { let r = f.format_snippet(snippet_path); - if r.is_err() { - print_error_formatting(&formatter_name, info); + if let Err(e) = &r { + if let MdsfError::MissingBinary(binary) = e { + print_binary_not_in_path( + if &formatter_name == binary { + formatter_name + } else { + format!("{binary} ({formatter_name})") + } + .as_str(), + ); + + return Ok((false, None)); + } else if matches!(e, MdsfError::FormatterError) { + print_error_formatting(&formatter_name, info); + return Ok((false, None)); + } } r diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index f40769f5..10375fe0 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -13,11 +13,11 @@ pub fn print_error(error: &MdsfError) { #[inline] pub fn print_formatter_info(formatter: &str, info: &LineInfo) { debug!( - "{} formatting '{}' block from :{} to :{} using {formatter}", + "{}:{} to :{} {} block using {formatter}", info.filename.display(), - info.language, info.start, - info.end + info.end, + info.language ); } @@ -51,13 +51,15 @@ pub fn print_unknown_javascript_runtime(value: u8, fallback: JavaScriptRuntime) #[inline] pub fn print_binary_not_in_path(binary_name: &str) { - warn!("'{binary_name}' not found in path"); + warn!("{binary_name} not found in path"); } #[inline] pub fn print_error_formatting(formatter_name: &str, info: &LineInfo) { error!( - "{} error formatting using {formatter_name}", + "{}:{} to :{} error formatting using {formatter_name}", info.filename.display(), + info.start, + info.end ); }