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