lsmem: better error messages in case of file read error
This commit is contained in:
		@@ -686,11 +686,15 @@ fn read_file_content<T: core::str::FromStr>(path: &Path) -> io::Result<T>
 | 
				
			|||||||
where
 | 
					where
 | 
				
			||||||
    T::Err: std::fmt::Debug, // Required to unwrap the result of T::from_str
 | 
					    T::Err: std::fmt::Debug, // Required to unwrap the result of T::from_str
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let file = fs::File::open(path)?;
 | 
					    let file = fs::File::open(path).expect("Failed to open file");
 | 
				
			||||||
    let mut reader = BufReader::new(file);
 | 
					    let mut reader = BufReader::new(file);
 | 
				
			||||||
    let mut content = String::new();
 | 
					    let mut content = String::new();
 | 
				
			||||||
    reader.read_line(&mut content)?;
 | 
					    reader.read_line(&mut content).expect("Failed to read line");
 | 
				
			||||||
    Ok(content.trim().to_string().parse().unwrap())
 | 
					    content
 | 
				
			||||||
 | 
					        .trim()
 | 
				
			||||||
 | 
					        .to_string()
 | 
				
			||||||
 | 
					        .parse()
 | 
				
			||||||
 | 
					        .map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "Failed to parse content"))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[uucore::main]
 | 
					#[uucore::main]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user