diff options
Diffstat (limited to 'cli/fmt.rs')
-rw-r--r-- | cli/fmt.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/cli/fmt.rs b/cli/fmt.rs index 28fdf9e66..e225b328b 100644 --- a/cli/fmt.rs +++ b/cli/fmt.rs @@ -11,7 +11,8 @@ use crate::colors; use crate::diff::diff; use crate::fs::files_in_subtree; use crate::text_encoding; -use deno_core::ErrBox; +use deno_core::error::generic_error; +use deno_core::error::AnyError; use dprint_plugin_typescript as dprint; use std::fs; use std::io::stdin; @@ -33,7 +34,7 @@ pub async fn format( args: Vec<String>, check: bool, exclude: Vec<String>, -) -> Result<(), ErrBox> { +) -> Result<(), AnyError> { if args.len() == 1 && args[0] == "-" { return format_stdin(check); } @@ -56,7 +57,7 @@ pub async fn format( async fn check_source_files( config: dprint::configuration::Configuration, paths: Vec<PathBuf>, -) -> Result<(), ErrBox> { +) -> Result<(), AnyError> { let not_formatted_files_count = Arc::new(AtomicUsize::new(0)); let checked_files_count = Arc::new(AtomicUsize::new(0)); @@ -116,7 +117,7 @@ async fn check_source_files( Ok(()) } else { let not_formatted_files_str = files_str(not_formatted_files_count); - Err(ErrBox::error(format!( + Err(generic_error(format!( "Found {} not formatted {} in {}", not_formatted_files_count, not_formatted_files_str, checked_files_str, ))) @@ -126,7 +127,7 @@ async fn check_source_files( async fn format_source_files( config: dprint::configuration::Configuration, paths: Vec<PathBuf>, -) -> Result<(), ErrBox> { +) -> Result<(), AnyError> { let formatted_files_count = Arc::new(AtomicUsize::new(0)); let checked_files_count = Arc::new(AtomicUsize::new(0)); let output_lock = Arc::new(Mutex::new(0)); // prevent threads outputting at the same time @@ -184,10 +185,10 @@ async fn format_source_files( /// Format stdin and write result to stdout. /// Treats input as TypeScript. /// Compatible with `--check` flag. -fn format_stdin(check: bool) -> Result<(), ErrBox> { +fn format_stdin(check: bool) -> Result<(), AnyError> { let mut source = String::new(); if stdin().read_to_string(&mut source).is_err() { - return Err(ErrBox::error("Failed to read from stdin")); + return Err(generic_error("Failed to read from stdin")); } let config = get_config(); @@ -203,7 +204,7 @@ fn format_stdin(check: bool) -> Result<(), ErrBox> { } } Err(e) => { - return Err(ErrBox::error(e)); + return Err(generic_error(e)); } } Ok(()) @@ -261,7 +262,7 @@ struct FileContents { had_bom: bool, } -fn read_file_contents(file_path: &Path) -> Result<FileContents, ErrBox> { +fn read_file_contents(file_path: &Path) -> Result<FileContents, AnyError> { let file_bytes = fs::read(&file_path)?; let charset = text_encoding::detect_charset(&file_bytes); let file_text = text_encoding::convert_to_utf8(&file_bytes, charset)?; @@ -279,7 +280,7 @@ fn read_file_contents(file_path: &Path) -> Result<FileContents, ErrBox> { fn write_file_contents( file_path: &Path, file_contents: FileContents, -) -> Result<(), ErrBox> { +) -> Result<(), AnyError> { let file_text = if file_contents.had_bom { // add back the BOM format!("{}{}", BOM_CHAR, file_contents.text) @@ -293,9 +294,9 @@ fn write_file_contents( pub async fn run_parallelized<F>( file_paths: Vec<PathBuf>, f: F, -) -> Result<(), ErrBox> +) -> Result<(), AnyError> where - F: FnOnce(PathBuf) -> Result<(), ErrBox> + Send + 'static + Clone, + F: FnOnce(PathBuf) -> Result<(), AnyError> + Send + 'static + Clone, { let handles = file_paths.iter().map(|file_path| { let f = f.clone(); |