Skip to content

Commit bb53f24

Browse files
committed
Rewrite some expect panic messages
1 parent c740772 commit bb53f24

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/io/cpal.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,23 @@ impl AudioBackendManager for CpalBackend {
132132

133133
let device = if options.sink_id.is_empty() {
134134
host.default_output_device()
135-
.expect("no output device available")
135+
.expect("InvalidStateError - no output device available")
136136
} else {
137137
Self::enumerate_devices_sync()
138138
.into_iter()
139139
.find(|e| e.device_id() == options.sink_id)
140140
.map(|e| *e.device().downcast::<cpal::Device>().unwrap())
141141
.unwrap_or_else(|| {
142142
host.default_output_device()
143-
.expect("no output device available")
143+
.expect("InvalidStateError - no output device available")
144144
})
145145
};
146146

147147
log::info!("Output device: {:?}", device.name());
148148

149149
let default_device_config = device
150150
.default_output_config()
151-
.expect("error while querying config");
151+
.expect("InvalidStateError - error while querying device output config");
152152

153153
// we grab the largest number of channels provided by the soundcard
154154
// clamped to MAX_CHANNELS, this value cannot be changed by the user
@@ -247,11 +247,15 @@ impl AudioBackendManager for CpalBackend {
247247
Arc::clone(&output_latency),
248248
);
249249

250-
spawned.expect("OutputStream build failed with default config")
250+
spawned
251+
.expect("InvalidStateError - Unable to spawn output stream with default config")
251252
}
252253
};
253254

254-
stream.play().expect("Stream refused to play");
255+
// Required because some hosts don't play the stream automatically
256+
stream
257+
.play()
258+
.expect("InvalidStateError - Output stream refused to play");
255259

256260
CpalBackend {
257261
stream: ThreadSafeClosableStream::new(stream),
@@ -272,23 +276,23 @@ impl AudioBackendManager for CpalBackend {
272276

273277
let device = if options.sink_id.is_empty() {
274278
host.default_input_device()
275-
.expect("no input device available")
279+
.expect("InvalidStateError - no input device available")
276280
} else {
277281
Self::enumerate_devices_sync()
278282
.into_iter()
279283
.find(|e| e.device_id() == options.sink_id)
280284
.map(|e| *e.device().downcast::<cpal::Device>().unwrap())
281285
.unwrap_or_else(|| {
282286
host.default_input_device()
283-
.expect("no input device available")
287+
.expect("InvalidStateError - no input device available")
284288
})
285289
};
286290

287291
log::info!("Input device: {:?}", device.name());
288292

289293
let supported = device
290294
.default_input_config()
291-
.expect("error while querying configs");
295+
.expect("InvalidStateError - error while querying device input config");
292296

293297
// clone the config, we may need to fall back on it later
294298
let mut preferred: StreamConfig = supported.clone().into();
@@ -349,12 +353,15 @@ impl AudioBackendManager for CpalBackend {
349353
&supported_config,
350354
renderer,
351355
);
352-
spawned.expect("Unable to spawn input stream with default config")
356+
spawned
357+
.expect("InvalidStateError - Unable to spawn input stream with default config")
353358
}
354359
};
355360

356361
// Required because some hosts don't play the stream automatically
357-
stream.play().expect("Input stream refused to play");
362+
stream
363+
.play()
364+
.expect("InvalidStateError - Input stream refused to play");
358365

359366
let backend = CpalBackend {
360367
stream: ThreadSafeClosableStream::new(stream),

src/io/cubeb.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ fn init_output_backend<const N: usize>(
132132
println!("stream state changed: {state:?}");
133133
});
134134

135-
let stream = builder.init(ctx).expect("Failed to create cubeb stream");
135+
let stream = builder
136+
.init(ctx)
137+
.expect("InvalidStateError - Failed to create cubeb stream");
136138
ThreadSafeClosableStream::new(stream)
137139
}
138140

@@ -346,7 +348,9 @@ impl AudioBackendManager for CubebBackend {
346348
println!("stream state changed: {state:?}");
347349
});
348350

349-
let stream = builder.init(&ctx).expect("Failed to create cubeb stream");
351+
let stream = builder
352+
.init(&ctx)
353+
.expect("InvalidStateError - Failed to create cubeb stream");
350354

351355
stream.start().unwrap();
352356

src/node/media_element_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl MediaElementAudioSourceNode {
9191
let stream = options
9292
.media_element
9393
.take_stream()
94-
.expect("stream already taken");
94+
.expect("InvalidStateError - stream already taken");
9595

9696
let resampler = Resampler::new(context.sample_rate(), RENDER_QUANTUM_SIZE, stream);
9797

0 commit comments

Comments
 (0)