fix(m1): move mut rx inside async block (clippy), log+continue on parse errors in load()
This commit is contained in:
parent
2706b2367d
commit
c3958553a5
2 changed files with 24 additions and 16 deletions
|
|
@ -51,11 +51,12 @@ pub fn run() {
|
||||||
.map(|pf| pf.log_paths.clone())
|
.map(|pf| pf.log_paths.clone())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut rx = watcher::spawn(log_paths);
|
let rx = watcher::spawn(log_paths);
|
||||||
let pf = Arc::new(pattern_file);
|
let pf = Arc::new(pattern_file);
|
||||||
let app_handle = app.handle().clone();
|
let app_handle = app.handle().clone();
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
|
let mut rx = rx;
|
||||||
while let Some(event) = rx.recv().await {
|
while let Some(event) = rx.recv().await {
|
||||||
if let Some(ref pf) = *pf {
|
if let Some(ref pf) = *pf {
|
||||||
if let Some(matched) = patterns::classify(&event, pf) {
|
if let Some(matched) = patterns::classify(&event, pf) {
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,17 @@ pub fn load(source_os: &str, distro_family: &str) -> Result<PatternFile> {
|
||||||
format!("/usr/share/robin/patterns/{filename}"),
|
format!("/usr/share/robin/patterns/{filename}"),
|
||||||
];
|
];
|
||||||
for path in &candidates {
|
for path in &candidates {
|
||||||
if let Ok(content) = std::fs::read_to_string(path) {
|
let content = match std::fs::read_to_string(path) {
|
||||||
let pf: PatternFile =
|
Ok(c) => c,
|
||||||
toml::from_str(&content).with_context(|| format!("failed to parse {path}"))?;
|
Err(_) => continue,
|
||||||
|
};
|
||||||
|
let pf: PatternFile = match toml::from_str(&content) {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("patterns: failed to parse {path}: {e}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
for p in &pf.patterns {
|
for p in &pf.patterns {
|
||||||
anyhow::ensure!(
|
anyhow::ensure!(
|
||||||
!p.match_text.is_empty(),
|
!p.match_text.is_empty(),
|
||||||
|
|
@ -67,7 +75,6 @@ pub fn load(source_os: &str, distro_family: &str) -> Result<PatternFile> {
|
||||||
}
|
}
|
||||||
return Ok(pf);
|
return Ok(pf);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
anyhow::bail!("pattern file not found: {filename}")
|
anyhow::bail!("pattern file not found: {filename}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue