Skip to content

Commit

Permalink
Add descriptive error message for files with wrong size in header
Browse files Browse the repository at this point in the history
  • Loading branch information
martinber committed Nov 30, 2023
1 parent 631946d commit 5d6c7e4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/noaa_apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,19 @@ impl ToString for SatName {
///
/// Returns the Signal and its sample rate.
pub fn load(input_filename: &Path) -> err::Result<(Signal, Rate)> {
let (signal, input_spec) = wav::load_wav(input_filename)?;
let (signal, input_spec) = wav::load_wav(input_filename).map_err(
|err| {
if let err::Error::WavOpen(ref string) = err {
// The hound library sometimes cannot open files with incorrect sizes in the
// header, see https://github.com/ruuda/hound/issues/39
if string.contains("Failed to read enough bytes") {
return err::Error::WavOpen("Wrong file length in WAV header, try opening and \
saving the file in some audio editor like Audacity".to_string())
}
}
err
}
)?;

Ok((signal, Rate::hz(input_spec.sample_rate)))
}
Expand Down

0 comments on commit 5d6c7e4

Please sign in to comment.