refactor(utils): Add extra logging to read_file (#2742)

Have added some additional logging to the `read_file` util to make
debugging issues easier.
This commit is contained in:
Thomas O'Donnell 2021-05-18 23:30:00 +02:00 committed by GitHub
parent 1bef1da8d4
commit 1612212b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 7 deletions

View File

@ -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<P: AsRef<Path>>(file_name: P) -> Result<String> {
let mut file = File::open(file_name)?;
let mut data = String::new();
pub fn read_file<P: AsRef<Path> + Debug>(file_name: P) -> Result<String> {
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)]