summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-12-09 20:24:37 -0500
committerGitHub <noreply@github.com>2021-12-09 20:24:37 -0500
commitf530189c500b9f12c4c94e88eca23eab9ae0d970 (patch)
treee830ad2fa3432d65239922079f86960a98c7500e /cli/tools
parent616ff1d482894f5742463b89fbc8496196c82a64 (diff)
fix(watch): mitigate race condition between file write by other process and watch read (#13038)
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/fmt.rs4
1 files changed, 3 insertions, 1 deletions
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<FileContents, AnyError> {
- 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);