summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2019-04-01 11:10:10 +0200
committerLinus Färnstrand <linus@mullvad.net>2019-04-01 23:19:33 +0200
commit5a6a7131c5ea786aca0831475763d9a2843fac45 (patch)
treeed961177d5eb6ae339b1afeaba1a3f571511c91a
parent9252bbdde62db9db5d564b785fbaac14220d085a (diff)
downloadmullvadvpn-5a6a7131c5ea786aca0831475763d9a2843fac45.tar.xz
mullvadvpn-5a6a7131c5ea786aca0831475763d9a2843fac45.zip
Create better error type for talpid_core::logging
-rw-r--r--mullvad-daemon/src/logging.rs4
-rw-r--r--talpid-core/src/logging.rs18
2 files changed, 13 insertions, 9 deletions
diff --git a/mullvad-daemon/src/logging.rs b/mullvad-daemon/src/logging.rs
index 39f5a2cd59..a12c83be30 100644
--- a/mullvad-daemon/src/logging.rs
+++ b/mullvad-daemon/src/logging.rs
@@ -14,10 +14,8 @@ error_chain! {
display("Unable to open log file for writing: {}", path.display())
}
}
- links {
- RotateLog(::talpid_core::logging::Error, ::talpid_core::logging::ErrorKind);
- }
foreign_links {
+ RotateLog(::talpid_core::logging::RotateLogError);
SetLoggerError(log::SetLoggerError);
Io(io::Error);
}
diff --git a/talpid-core/src/logging.rs b/talpid-core/src/logging.rs
index 9f63c70a33..b41e1a3ffc 100644
--- a/talpid-core/src/logging.rs
+++ b/talpid-core/src/logging.rs
@@ -1,19 +1,25 @@
use std::{fs, io, path::Path};
-error_chain! {}
+/// Unable to create new log file
+#[derive(err_derive::Error, Debug)]
+#[error(display = "Unable to create new log file")]
+pub struct RotateLogError(#[error(cause)] io::Error);
/// Create a new log file while backing up a previous version of it.
///
/// A new log file is created with the given file name, but if a file with that name already exists
/// it is backed up with the extension changed to `.old.log`.
-pub fn rotate_log(file: &Path) -> Result<()> {
+pub fn rotate_log(file: &Path) -> Result<(), RotateLogError> {
let backup = file.with_extension("old.log");
- if let Err(error) = fs::rename(file, backup) {
+ if let Err(error) = fs::rename(file, &backup) {
if error.kind() != io::ErrorKind::NotFound {
- log::warn!("Failed to rotate log file ({})", error);
+ log::warn!(
+ "Failed to rotate log file to {}: {}",
+ backup.display(),
+ error
+ );
}
}
- fs::File::create(file).chain_err(|| "Unable to create new log file")?;
- Ok(())
+ fs::File::create(file).map(|_| ()).map_err(RotateLogError)
}