1
0
mirror of https://github.com/danog/libdvb.git synced 2024-11-26 20:04:39 +01:00

More and better context

This commit is contained in:
Daniil Gentili 2022-03-22 20:42:00 +01:00
parent a33cd90986
commit 086d025e00
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 6 additions and 6 deletions

View File

@ -82,16 +82,16 @@ impl AsRawFd for FeDevice {
#[macro_export]
macro_rules! get_dtv_properties {
( $device:expr, $( $property:ident ),+ ) => { (|| -> anyhow::Result<_> {
( $device:expr, $( $property:ident ),+ ) => { (|| -> ::anyhow::Result<_> {
let mut input = [ $( $property(DtvPropertyRequest::default()), )* ];
$device.get_properties(&mut input)?;
$device.get_properties(&mut input).context("Error fetching properties")?;
let mut iterator = input.iter();
Ok((
$(
match iterator.next() {
Some($property(d)) => d.get(),
_ => ::anyhow::Result::Err(anyhow!("Error unpacking")),
}?,
_ => ::anyhow::Result::Err(anyhow!("Missing value")),
}.with_context(|| format!("Error unpacking {}", stringify!($property)))?,
)*
))
})()}

View File

@ -2,7 +2,7 @@ use crate::get_dtv_properties;
use {
super::{sys::*, FeDevice},
anyhow::Result,
anyhow::{Context, Result},
std::fmt,
};

View File

@ -868,7 +868,7 @@ macro_rules! dtv_property {
#[macro_export]
macro_rules! dtv_property_parse {
( $property:ident($data:expr)) => {
$property(DtvPropertyRequest::new($data.parse().context(format!("Invalid {}: {}", stringify!($property), $data))?))
$property(DtvPropertyRequest::new($data.parse().with_context(||format!("Invalid {}: {}", stringify!($property), $data))?))
};
}