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())
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut rx = watcher::spawn(log_paths);
|
||||
let rx = watcher::spawn(log_paths);
|
||||
let pf = Arc::new(pattern_file);
|
||||
let app_handle = app.handle().clone();
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let mut rx = rx;
|
||||
while let Some(event) = rx.recv().await {
|
||||
if let Some(ref pf) = *pf {
|
||||
if let Some(matched) = patterns::classify(&event, pf) {
|
||||
|
|
|
|||
|
|
@ -50,23 +50,30 @@ pub fn load(source_os: &str, distro_family: &str) -> Result<PatternFile> {
|
|||
format!("/usr/share/robin/patterns/{filename}"),
|
||||
];
|
||||
for path in &candidates {
|
||||
if let Ok(content) = std::fs::read_to_string(path) {
|
||||
let pf: PatternFile =
|
||||
toml::from_str(&content).with_context(|| format!("failed to parse {path}"))?;
|
||||
for p in &pf.patterns {
|
||||
anyhow::ensure!(
|
||||
!p.match_text.is_empty(),
|
||||
"pattern '{}' has empty match_text in {path}",
|
||||
p.id
|
||||
);
|
||||
anyhow::ensure!(
|
||||
!p.sources.is_empty(),
|
||||
"pattern '{}' has empty sources list in {path}",
|
||||
p.id
|
||||
);
|
||||
let content = match std::fs::read_to_string(path) {
|
||||
Ok(c) => c,
|
||||
Err(_) => continue,
|
||||
};
|
||||
let pf: PatternFile = match toml::from_str(&content) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
log::warn!("patterns: failed to parse {path}: {e}");
|
||||
continue;
|
||||
}
|
||||
return Ok(pf);
|
||||
};
|
||||
for p in &pf.patterns {
|
||||
anyhow::ensure!(
|
||||
!p.match_text.is_empty(),
|
||||
"pattern '{}' has empty match_text in {path}",
|
||||
p.id
|
||||
);
|
||||
anyhow::ensure!(
|
||||
!p.sources.is_empty(),
|
||||
"pattern '{}' has empty sources list in {path}",
|
||||
p.id
|
||||
);
|
||||
}
|
||||
return Ok(pf);
|
||||
}
|
||||
anyhow::bail!("pattern file not found: {filename}")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue