summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-10-26 21:14:39 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-10-26 21:35:20 +0200
commite8d90444b5b9bbd0bb8bbd1552c0c4844dde3451 (patch)
treebf87bc2afb071aeb854ff0be6ec3a77c1db993ed
parent83510d2dc666e79d718a767679426ae12dd60eb1 (diff)
downloadmullvadvpn-e8d90444b5b9bbd0bb8bbd1552c0c4844dde3451.tar.xz
mullvadvpn-e8d90444b5b9bbd0bb8bbd1552c0c4844dde3451.zip
Simplify problem report log adding
-rw-r--r--mullvad-daemon/src/bin/problem-report.rs34
1 files changed, 12 insertions, 22 deletions
diff --git a/mullvad-daemon/src/bin/problem-report.rs b/mullvad-daemon/src/bin/problem-report.rs
index a4b5107dec..ef9534b7cb 100644
--- a/mullvad-daemon/src/bin/problem-report.rs
+++ b/mullvad-daemon/src/bin/problem-report.rs
@@ -116,8 +116,8 @@ fn run() -> Result<()> {
fn collect_report(log_paths: Vec<PathBuf>, save_path: PathBuf) -> Result<()> {
let mut problem_report = ProblemReport::default();
- for log_path in log_paths.into_iter() {
- problem_report.add_file_log(log_path);
+ for log_path in &log_paths {
+ problem_report.add_log(log_path);
}
write_problem_report(&save_path, problem_report)
.chain_err(|| ErrorKind::WriteReportError(save_path.clone()))
@@ -147,31 +147,21 @@ struct ProblemReport {
}
impl ProblemReport {
- /// Attach file log to this report
- /// Unlike `try_add_file_log` this method uses the error description
- /// instead of log contents if error occurred when reading log file.
- fn add_file_log(&mut self, path: PathBuf) {
- if let Err(e) = self.try_add_file_log(&path)
- .chain_err(|| ErrorKind::ReadLogError(path.clone()))
- {
- self.logs.push((
- path.to_string_lossy().into_owned(),
- e.display_chain().to_string(),
- ));
- }
- }
-
- /// Try reading log from file source and attach it to this report
- fn try_add_file_log(&mut self, path: &Path) -> io::Result<()> {
- Ok(self.logs.push((
+ /// Attach file log to this report. This method uses the error chain instead of log contents if
+ /// error occurred when reading log file.
+ fn add_log(&mut self, path: &Path) {
+ let content = Self::read_file_lossy(path, LOG_MAX_READ_BYTES)
+ .chain_err(|| ErrorKind::ReadLogError(path.to_path_buf()))
+ .unwrap_or_else(|e| e.display_chain().to_string());
+ self.logs.push((
path.to_string_lossy().into_owned(),
- Self::read_log_file(path, LOG_MAX_READ_BYTES)?,
- )))
+ content,
+ ));
}
/// Private helper to safely read the given number of bytes off the tail of UTF-8 log file
/// and return it as a string
- fn read_log_file(path: &Path, max_bytes: usize) -> io::Result<String> {
+ fn read_file_lossy(path: &Path, max_bytes: usize) -> io::Result<String> {
let mut file = File::open(path)?;
let file_size = file.metadata()?.len();