From 1612212b63c8af10cf6a25f419235b6eef2f1699 Mon Sep 17 00:00:00 2001 From: Thomas O'Donnell Date: Tue, 18 May 2021 23:30:00 +0200 Subject: [PATCH] refactor(utils): Add extra logging to read_file (#2742) Have added some additional logging to the `read_file` util to make debugging issues easier. --- src/utils.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index a70192e3..2c32c09a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,7 @@ use process_control::{ChildExt, Timeout}; -use std::fs::File; -use std::io::{Read, Result}; +use std::fmt::Debug; +use std::fs::read_to_string; +use std::io::Result; use std::path::Path; use std::process::{Command, Stdio}; use std::time::{Duration, Instant}; @@ -8,12 +9,18 @@ use std::time::{Duration, Instant}; use crate::context::Shell; /// Return the string contents of a file -pub fn read_file>(file_name: P) -> Result { - let mut file = File::open(file_name)?; - let mut data = String::new(); +pub fn read_file + Debug>(file_name: P) -> Result { + log::trace!("Trying to read from {:?}", file_name); - file.read_to_string(&mut data)?; - Ok(data) + let result = read_to_string(file_name); + + if result.is_err() { + log::debug!("Error reading file: {:?}", result); + } else { + log::trace!("File read sucessfully"); + }; + + result } #[derive(Debug, Clone)]