Optimize various error message / debug message formatting

Directly make use of format strings instead of formatting a string
beforehand and then passing it to the macros.
This commit is contained in:
Sebastian Dröge 2023-02-13 11:50:57 +02:00
parent 034c0f0fd8
commit 04e101c605
12 changed files with 34 additions and 40 deletions

View file

@ -209,12 +209,12 @@ impl ClaxonDec {
indata: &[u8], indata: &[u8],
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let streaminfo = claxon_streaminfo(indata).map_err(|e| { let streaminfo = claxon_streaminfo(indata).map_err(|e| {
gst::element_imp_error!(self, gst::StreamError::Decode, [e]); gst::element_imp_error!(self, gst::StreamError::Decode, ["{e}"]);
gst::FlowError::Error gst::FlowError::Error
})?; })?;
let audio_info = gstaudioinfo(&streaminfo).map_err(|e| { let audio_info = gstaudioinfo(&streaminfo).map_err(|e| {
gst::element_imp_error!(self, gst::StreamError::Decode, [&e]); gst::element_imp_error!(self, gst::StreamError::Decode, ["{e}"]);
gst::FlowError::Error gst::FlowError::Error
})?; })?;

View file

@ -144,11 +144,11 @@ impl CsoundFilter {
if let Some(ref location) = settings.location { if let Some(ref location) = settings.location {
csound csound
.compile_csd(location) .compile_csd(location)
.map_err(|e| error_msg!(gst::LibraryError::Failed, [e]))?; .map_err(|e| error_msg!(gst::LibraryError::Failed, ["{e}"]))?;
} else if let Some(ref text) = settings.csd_text { } else if let Some(ref text) = settings.csd_text {
csound csound
.compile_csd_text(text) .compile_csd_text(text)
.map_err(|e| error_msg!(gst::LibraryError::Failed, [e]))?; .map_err(|e| error_msg!(gst::LibraryError::Failed, ["{e}"]))?;
} else { } else {
return Err(error_msg!( return Err(error_msg!(
gst::LibraryError::Failed, gst::LibraryError::Failed,
@ -470,7 +470,7 @@ impl BaseTransformImpl for CsoundFilter {
csound.set_score_offset_seconds(settings.offset); csound.set_score_offset_seconds(settings.offset);
if let Err(e) = csound.start() { if let Err(e) = csound.start() {
return Err(error_msg!(gst::LibraryError::Failed, [e])); return Err(error_msg!(gst::LibraryError::Failed, ["{e}"]));
} }
Ok(()) Ok(())

View file

@ -324,9 +324,8 @@ impl PushSrcImpl for SpotifyAudioSrc {
return Err(gst::FlowError::Flushing); return Err(gst::FlowError::Flushing);
} }
Ok(Err(err)) => { Ok(Err(err)) => {
let details = format!("{err:?}"); gst::error!(CAT, imp: self, "failed to start: {err:?}");
gst::error!(CAT, imp: self, "failed to start: {}", details); gst::element_imp_error!(self, gst::ResourceError::Settings, ["{err:?}"]);
gst::element_imp_error!(self, gst::ResourceError::Settings, [&details]);
return Err(gst::FlowError::Error); return Err(gst::FlowError::Error);
} }
Ok(Ok(_)) => {} Ok(Ok(_)) => {}

View file

@ -61,11 +61,10 @@ impl State {
.ok_or_else(|| { .ok_or_else(|| {
gst::error_msg!( gst::error_msg!(
gst::ResourceError::NotFound, gst::ResourceError::NotFound,
[format!( [
"Failed to set Sender's Key from property: {:?}", "Failed to set Sender's Key from property: {:?}",
props.sender_key props.sender_key
) ]
.as_ref()]
) )
})?; })?;
@ -76,11 +75,10 @@ impl State {
.ok_or_else(|| { .ok_or_else(|| {
gst::error_msg!( gst::error_msg!(
gst::ResourceError::NotFound, gst::ResourceError::NotFound,
[format!( [
"Failed to set Receiver's Key from property: {:?}", "Failed to set Receiver's Key from property: {:?}",
props.receiver_key props.receiver_key
) ]
.as_ref()]
) )
})?; })?;

View file

@ -76,11 +76,10 @@ impl State {
.ok_or_else(|| { .ok_or_else(|| {
gst::error_msg!( gst::error_msg!(
gst::ResourceError::NotFound, gst::ResourceError::NotFound,
[format!( [
"Failed to set Sender's Key from property: {:?}", "Failed to set Sender's Key from property: {:?}",
props.sender_key props.sender_key
) ]
.as_ref()]
) )
})?; })?;
@ -91,11 +90,10 @@ impl State {
.ok_or_else(|| { .ok_or_else(|| {
gst::error_msg!( gst::error_msg!(
gst::ResourceError::NotFound, gst::ResourceError::NotFound,
[format!( [
"Failed to set Receiver's Key from property: {:?}", "Failed to set Receiver's Key from property: {:?}",
props.receiver_key props.receiver_key
) ]
.as_ref()]
) )
})?; })?;

View file

@ -403,8 +403,8 @@ impl BinImpl for WhepSrc {
impl WhepSrc { impl WhepSrc {
fn raise_error(&self, resource_error: gst::ResourceError, msg: String) { fn raise_error(&self, resource_error: gst::ResourceError, msg: String) {
gst::error_msg!(resource_error, [msg.as_str()]); gst::error_msg!(resource_error, ["{msg}"]);
gst::element_imp_error!(self, resource_error, [msg.as_str()]); gst::element_imp_error!(self, resource_error, ["{msg}"]);
} }
fn handle_future_error(&self, err: WaitError) { fn handle_future_error(&self, err: WaitError) {

View file

@ -499,8 +499,8 @@ impl ObjectSubclass for WhipSink {
impl WhipSink { impl WhipSink {
fn raise_error(&self, resource_error: gst::ResourceError, msg: String) { fn raise_error(&self, resource_error: gst::ResourceError, msg: String) {
gst::error_msg!(resource_error, [msg.as_str()]); gst::error_msg!(resource_error, ["{msg}"]);
gst::element_imp_error!(self, resource_error, [msg.as_str()]); gst::element_imp_error!(self, resource_error, ["{msg}"]);
} }
fn handle_future_error(&self, err: WaitError) { fn handle_future_error(&self, err: WaitError) {

View file

@ -1623,14 +1623,13 @@ impl UriPlaylistBin {
blocked.set_streaming(state.streams_topology.n_streams()); blocked.set_streaming(state.streams_topology.n_streams());
} }
} }
let error_msg = error.to_string(); gst::error!(CAT, imp: self, "{error}");
gst::error!(CAT, imp: self, "{}", error_msg);
match error { match error {
PlaylistError::PluginMissing { .. } => { PlaylistError::PluginMissing { .. } => {
gst::element_imp_error!(self, gst::CoreError::MissingPlugin, [&error_msg]); gst::element_imp_error!(self, gst::CoreError::MissingPlugin, ["{error}"]);
} }
PlaylistError::ItemFailed { item, .. } => { PlaylistError::ItemFailed { ref item, .. } => {
// remove failing uridecodebin // remove failing uridecodebin
let uridecodebin = item.uridecodebin(); let uridecodebin = item.uridecodebin();
uridecodebin.call_async(move |uridecodebin| { uridecodebin.call_async(move |uridecodebin| {
@ -1644,7 +1643,7 @@ impl UriPlaylistBin {
gst::element_imp_error!( gst::element_imp_error!(
self, self,
gst::LibraryError::Failed, gst::LibraryError::Failed,
[&error_msg], ["{error}"],
details: details.build() details: details.build()
); );
} }

View file

@ -363,8 +363,8 @@ impl BaseTransformImpl for CCDetect {
let cc_packet = match self.detect(format, map.as_slice()) { let cc_packet = match self.detect(format, map.as_slice()) {
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
gst::warning!(CAT, imp: self, "{}", &e.to_string()); gst::warning!(CAT, imp: self, "{e}");
gst::element_imp_warning!(self, gst::StreamError::Decode, [&e.to_string()]); gst::element_imp_warning!(self, gst::StreamError::Decode, ["{e}"]);
CCPacketContents { CCPacketContents {
cc608: false, cc608: false,
cc708: false, cc708: false,

View file

@ -419,8 +419,8 @@ impl Cea608Overlay {
self.decode_cc_data(pad, &mut state, data, pts); self.decode_cc_data(pad, &mut state, data, pts);
} }
Err(e) => { Err(e) => {
gst::warning!(CAT, "{}", &e.to_string()); gst::warning!(CAT, "{e}");
gst::element_imp_warning!(self, gst::StreamError::Decode, [&e.to_string()]); gst::element_imp_warning!(self, gst::StreamError::Decode, ["{e}"]);
} }
} }
} else if meta.caption_type() == gst_video::VideoCaptionType::Cea708Raw { } else if meta.caption_type() == gst_video::VideoCaptionType::Cea708Raw {

View file

@ -380,7 +380,7 @@ impl VideoEncoderImpl for GifEnc {
// encode new frame // encode new frame
let context = state.context.as_mut().unwrap(); let context = state.context.as_mut().unwrap();
if let Err(e) = context.write_frame(&gif_frame) { if let Err(e) = context.write_frame(&gif_frame) {
gst::element_imp_error!(self, gst::CoreError::Failed, [&e.to_string()]); gst::element_imp_error!(self, gst::CoreError::Failed, ["{e}"]);
return Err(gst::FlowError::Error); return Err(gst::FlowError::Error);
} }
} }

View file

@ -232,8 +232,8 @@ impl VideoEncoderImpl for PngEncoder {
encoder.set_filter(png::FilterType::from(settings.filter)); encoder.set_filter(png::FilterType::from(settings.filter));
let mut writer = encoder.write_header().map_err(|e| { let mut writer = encoder.write_header().map_err(|e| {
gst::error!(CAT, imp: self, "Failed to create encoder: {}", e); gst::error!(CAT, imp: self, "Failed to create encoder: {e}");
gst::element_imp_error!(self, gst::CoreError::Failed, [&e.to_string()]); gst::element_imp_error!(self, gst::CoreError::Failed, ["{e}"]);
gst::FlowError::Error gst::FlowError::Error
})?; })?;
@ -241,15 +241,15 @@ impl VideoEncoderImpl for PngEncoder {
let input_buffer = frame.input_buffer().expect("frame without input buffer"); let input_buffer = frame.input_buffer().expect("frame without input buffer");
let input_map = input_buffer.map_readable().unwrap(); let input_map = input_buffer.map_readable().unwrap();
writer.write_image_data(&input_map).map_err(|e| { writer.write_image_data(&input_map).map_err(|e| {
gst::error!(CAT, imp: self, "Failed to write image data: {}", e); gst::error!(CAT, imp: self, "Failed to write image data: {e}");
gst::element_imp_error!(self, gst::CoreError::Failed, [&e.to_string()]); gst::element_imp_error!(self, gst::CoreError::Failed, ["{e}"]);
gst::FlowError::Error gst::FlowError::Error
})?; })?;
} }
writer.finish().map_err(|e| { writer.finish().map_err(|e| {
gst::error!(CAT, imp: self, "Failed to finish encoder: {}", e); gst::error!(CAT, imp: self, "Failed to finish encoder: {e}");
gst::element_imp_error!(self, gst::CoreError::Failed, [&e.to_string()]); gst::element_imp_error!(self, gst::CoreError::Failed, ["{e}"]);
gst::FlowError::Error gst::FlowError::Error
})?; })?;