log err on NaN instead of panicking
This commit is contained in:
parent
49f02fd617
commit
674f7e49d2
1 changed files with 6 additions and 6 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue