From f530189c500b9f12c4c94e88eca23eab9ae0d970 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 9 Dec 2021 20:24:37 -0500 Subject: fix(watch): mitigate race condition between file write by other process and watch read (#13038) --- cli/tools/fmt.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cli/tools') diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 2149552cd..9172421b5 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -19,6 +19,7 @@ use crate::fs_util::specifier_to_file_path; use crate::fs_util::{collect_files, get_extension, is_supported_ext_fmt}; use crate::text_encoding; use deno_ast::ParsedSource; +use deno_core::anyhow::Context; use deno_core::error::generic_error; use deno_core::error::AnyError; use deno_core::futures; @@ -525,7 +526,8 @@ struct FileContents { } fn read_file_contents(file_path: &Path) -> Result { - let file_bytes = fs::read(&file_path)?; + let file_bytes = fs::read(&file_path) + .with_context(|| format!("Error reading {}", file_path.display()))?; let charset = text_encoding::detect_charset(&file_bytes); let file_text = text_encoding::convert_to_utf8(&file_bytes, charset)?; let had_bom = file_text.starts_with(text_encoding::BOM_CHAR); -- cgit v1.2.3