log err on NaN instead of panicking

This commit is contained in:
brevalferrari 2025-06-07 15:05:07 +02:00
parent 49f02fd617
commit 674f7e49d2

View file

@ -15,7 +15,7 @@ use clap::Parser as _;
use cli::Cli;
use dasp_sample::Sample;
use hound::{SampleFormat, WavSpec, WavWriter};
use log::{debug, info, warn};
use log::{debug, error, info, warn};
use rodio::{OutputStream, Sink, buffer::SamplesBuffer};
use crate::cli::{ExportOpts, PlayOpts};
@ -166,11 +166,11 @@ fn parse_and_compile(opts: &PlayOpts) -> anyhow::Result<Vec<f64>> {
compiler
.compile_all(tokens)
.inspect(|v| {
for sample in v {
assert!(
!sample.abs().is_nan(),
"Waiter! There's a NaN in my samples!"
);
let is_nan = |sample| sample.abs().is_nan();
if v.iter().all(is_nan) {
error!("🎉 All your samples are NaN, you got yourself a \"Not a Song\" (NaS)!")
} else if v.iter().any(is_nan) {
error!("Waiter! There's a NaN in my samples!");
}
})
.context("Failed to compile tokens to samples")