Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(log): propagte some errors and avoid unwrapping #1294

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions plugins/log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl Builder {
LogTarget::Stderr => fern::Output::from(std::io::stderr()),
LogTarget::Folder(path) => {
if !path.exists() {
fs::create_dir_all(path).unwrap();
fs::create_dir_all(path)?;
}

fern::log_file(get_log_file_path(
Expand All @@ -334,9 +334,12 @@ impl Builder {
.into()
}
LogTarget::LogDir => {
let path = app_handle.path_resolver().app_log_dir().unwrap();
let path = app_handle
.path_resolver()
.app_log_dir()
.ok_or("app_log_dir is None")?;
if !path.exists() {
fs::create_dir_all(&path).unwrap();
fs::create_dir_all(&path)?;
}

fern::log_file(get_log_file_path(
Expand All @@ -358,7 +361,7 @@ impl Builder {
};
let app_handle = app_handle.clone();
tauri::async_runtime::spawn(async move {
app_handle.emit_all("log://log", payload).unwrap();
let _ = app_handle.emit_all("log://log", payload);
});
})
}
Expand Down Expand Up @@ -392,21 +395,20 @@ fn get_log_file_path(
log_name,
timezone_strategy
.get_now()
.format(
&time::format_description::parse(
"[year]-[month]-[day]_[hour]-[minute]-[second]"
)
.unwrap()
)
.unwrap(),
.format(&time::format_description::parse(
"[year]-[month]-[day]_[hour]-[minute]-[second]"
)?)?,
));
if to.is_file() {
// designated rotated log file name already exists
// highly unlikely but defensively handle anyway by adding .bak to filename
let mut to_bak = to.clone();
to_bak.set_file_name(format!(
"{}.bak",
to_bak.file_name().unwrap().to_string_lossy()
to_bak
.file_name()
.map(|n| n.to_string_lossy())
.unwrap_or_default()
));
fs::rename(&to, to_bak)?;
}
Expand Down
Loading