Skip to content

Commit

Permalink
Better error message (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 authored Mar 19, 2024
1 parent e602334 commit 5f20711
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/avutil/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::ffi::{c_int, CStr};
/// Return `Some(description)` on success, a negative value if a description for
/// errnum cannot be found.
pub fn err2str(errnum: c_int) -> Option<String> {
// mimicks `av_err2str()`
const ERRBUF_SIZE: usize = AV_ERROR_MAX_STRING_SIZE as usize;
let mut errbuf = [0u8; ERRBUF_SIZE];
if unsafe { ffi::av_strerror(errnum, errbuf.as_mut_ptr() as _, ERRBUF_SIZE) } == 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::{
};
use thiserror::Error;

use crate::{ffi, shared::AVERROR_EAGAIN};
use crate::{avutil::err2str, ffi, shared::AVERROR_EAGAIN};

/// All the error variants of rsmpeg.
#[non_exhaustive]
#[derive(Error, Debug, Eq, PartialEq)]
pub enum RsmpegError {
#[error("AVERROR({0})")]
#[error("AVERROR({0}): `{}`", err2str(*.0).unwrap_or_else(|| "Unknown error code.".to_string()))]
AVError(c_int),
#[error("{0}")]
CustomError(String),
Expand Down

0 comments on commit 5f20711

Please sign in to comment.