1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 15:56:28 +00:00

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

View File

@ -1,6 +1,7 @@
use process_control::{ChildExt, Timeout}; use process_control::{ChildExt, Timeout};
use std::fs::File; use std::fmt::Debug;
use std::io::{Read, Result}; use std::fs::read_to_string;
use std::io::Result;
use std::path::Path; use std::path::Path;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -8,12 +9,18 @@ use std::time::{Duration, Instant};
use crate::context::Shell; use crate::context::Shell;
/// Return the string contents of a file /// Return the string contents of a file
pub fn read_file<P: AsRef<Path>>(file_name: P) -> Result<String> { pub fn read_file<P: AsRef<Path> + Debug>(file_name: P) -> Result<String> {
let mut file = File::open(file_name)?; log::trace!("Trying to read from {:?}", file_name);
let mut data = String::new();
file.read_to_string(&mut data)?; let result = read_to_string(file_name);
Ok(data)
if result.is_err() {
log::debug!("Error reading file: {:?}", result);
} else {
log::trace!("File read sucessfully");
};
result
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]