Skip to content

Commit 5f22931

Browse files
committed
update panic messages for consistency
1 parent 585f8aa commit 5f22931

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/node/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,18 @@ pub trait AudioNode {
366366
}
367367
}
368368

369+
#[track_caller]
370+
#[inline(always)]
371+
pub(create) fn assert_greater_then_f64(value: f64, minimum_bound: f64) {
372+
if !value.is_finite() {
373+
panic!("TypeError - The provided value is non-finite.");
374+
}
375+
376+
if value < 0. {
377+
panic!("RangeError - The offset value ({:?}) is less than the minimum bound (0).", value, minimum_bound);
378+
}
379+
}
380+
369381
/// Interface of source nodes, controlling start and stop times.
370382
/// The node will emit silence before it is started, and after it has ended.
371383
pub trait AudioScheduledSourceNode: AudioNode {
@@ -477,3 +489,25 @@ impl<R: AudioBufferIter> AudioProcessor for MediaStreamRenderer<R> {
477489
!self.finished
478490
}
479491
}
492+
493+
#[cfg(test)]
494+
mod tests {
495+
use super::*;
496+
497+
#[test]
498+
#[should_panic]
499+
fn test_assert_positive_f64_1() {
500+
assert_positive_f64(f64::NAN);
501+
}
502+
503+
#[test]
504+
#[should_panic]
505+
fn test_assert_positive_f64_1() {
506+
assert_positive_f64(-1.);
507+
}
508+
509+
#[test]
510+
fn test_assert_positive_f64_1() {
511+
assert_positive_f64(1.);
512+
}
513+
}

src/node/panner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ enum ControlMessage {
174174
#[inline(always)]
175175
fn assert_valid_channel_count(count: usize) {
176176
if count > 2 {
177-
panic!("NotSupportedError: PannerNode channel count cannot be greater than two");
177+
panic!("NotSupportedError - PannerNode channel count cannot be greater than two");
178178
}
179179
}
180180

@@ -189,7 +189,7 @@ fn assert_valid_channel_count(count: usize) {
189189
#[inline(always)]
190190
fn assert_valid_channel_count_mode(mode: ChannelCountMode) {
191191
if mode == ChannelCountMode::Max {
192-
panic!("NotSupportedError: PannerNode channel count mode cannot be set to max");
192+
panic!("NotSupportedError - PannerNode channel count mode cannot be set to max");
193193
}
194194
}
195195

src/node/stereo_panner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Default for StereoPannerOptions {
4444
#[inline(always)]
4545
fn assert_valid_channel_count(count: usize) {
4646
if count > 2 {
47-
panic!("NotSupportedError: StereoPannerNode channel count cannot be greater than two");
47+
panic!("NotSupportedError - StereoPannerNode channel count cannot be greater than two");
4848
}
4949
}
5050

@@ -59,7 +59,7 @@ fn assert_valid_channel_count(count: usize) {
5959
#[inline(always)]
6060
fn assert_valid_channel_count_mode(mode: ChannelCountMode) {
6161
if mode == ChannelCountMode::Max {
62-
panic!("NotSupportedError: StereoPannerNode channel count mode cannot be set to max");
62+
panic!("NotSupportedError - StereoPannerNode channel count mode cannot be set to max");
6363
}
6464
}
6565

0 commit comments

Comments
 (0)