Skip to main content

max / audiofiles

lint: deny clippy::unwrap_used in audiofiles-browser Continues the deny(unwrap_used) ratchet to the browser UI crate. Four production unwraps removed: - preview.rs (x2): the decode buffer's `= Some(..); as_mut().unwrap()` reallocation idiom replaced with Option::insert, which assigns and returns the &mut in one step. - state/library.rs (x2): the two save_* config serialisers now match on serde_json::to_string and log+skip on the (unreachable) Err instead of unwrapping — a save that can't serialise no longer panics the app. Crate is clean under #![cfg_attr(not(test), deny(clippy::unwrap_used))]; 256 tests green. Remaining: audiofiles-sync, audiofiles-core. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-07-11 17:11 UTC
Commit: 824428da5238e2cd972fca3c2c67e9f408e21010
Parent: 6f1d089
3 files changed, +25 insertions, -13 deletions
@@ -1,5 +1,10 @@
1 1 //! Browser UI for audiofiles — file browsing, import, preview, and waveform display.
2 2
3 + // Part of the deny(unwrap_used) ratchet (see audiofiles-app / audiofiles-rhai).
4 + // Forbid bare unwrap in production code; tests opt out. `expect` with a
5 + // justification stays allowed for documented invariants.
6 + #![cfg_attr(not(test), deny(clippy::unwrap_used))]
7 +
3 8 pub mod backend;
4 9 pub mod classifier_worker;
5 10 pub mod cleanup;
@@ -160,10 +160,7 @@ fn decode_to_f32(path: &Path) -> Result<PreviewBuffer, PreviewError> {
160 160 // Reallocate only when the buffer can't fit this packet.
161 161 let buf = match &mut sample_buf {
162 162 Some(buf) if buf.capacity() >= num_frames => buf,
163 - _ => {
164 - sample_buf = Some(SampleBuffer::<f32>::new(num_frames as u64, spec));
165 - sample_buf.as_mut().unwrap()
166 - }
163 + _ => sample_buf.insert(SampleBuffer::<f32>::new(num_frames as u64, spec)),
167 164 };
168 165 buf.copy_interleaved_ref(decoded);
169 166 let samples = buf.samples();
@@ -409,10 +406,7 @@ pub fn start_streaming_decode(
409 406
410 407 let buf = match &mut sample_buf {
411 408 Some(buf) if buf.capacity() >= num_frames => buf,
412 - _ => {
413 - sample_buf = Some(SampleBuffer::<f32>::new(num_frames as u64, spec));
414 - sample_buf.as_mut().unwrap()
415 - }
409 + _ => sample_buf.insert(SampleBuffer::<f32>::new(num_frames as u64, spec)),
416 410 };
417 411 buf.copy_interleaved_ref(decoded);
418 412 let samples = buf.samples();
@@ -409,8 +409,15 @@ impl BrowserState {
409 409
410 410 /// Persist the per-classification dismissed-suggestion map.
411 411 fn save_dismissed_suggestions(&self) {
412 - // unwrap is safe: HashMap<String, Vec<String>> serialises cleanly.
413 - let json = serde_json::to_string(&self.dismissed_suggestions).unwrap();
412 + let json = match serde_json::to_string(&self.dismissed_suggestions) {
413 + Ok(json) => json,
414 + Err(e) => {
415 + // HashMap<String, Vec<String>> serialises cleanly, so this is
416 + // unreachable; skip the save rather than panic if it ever isn't.
417 + tracing::error!("failed to serialise dismissed suggestions: {e}");
418 + return;
419 + }
420 + };
414 421 super::log_backend_err("set_config suggestions.dismissed", self.backend.set_config("suggestions.dismissed", &json));
415 422 }
416 423
@@ -466,9 +473,15 @@ impl BrowserState {
466 473
467 474 /// Save column config to the user_config table.
468 475 pub fn save_column_config(&self) {
469 - // unwrap is safe: ColumnConfig contains only primitive fields (bools, enums)
470 - // with derived Serialize impls, so serialisation cannot fail.
471 - let json = serde_json::to_string(&self.column_config).unwrap();
476 + let json = match serde_json::to_string(&self.column_config) {
477 + Ok(json) => json,
478 + Err(e) => {
479 + // ColumnConfig is primitive fields with derived Serialize, so this
480 + // is unreachable; skip the save rather than panic if it ever isn't.
481 + tracing::error!("failed to serialise column config: {e}");
482 + return;
483 + }
484 + };
472 485 super::log_backend_err("set_config column_config", self.backend.set_config("column_config", &json));
473 486 }
474 487