[FFmpeg-devel] [RFC] Internal error messages

Derek Buitenhuis derek.buitenhuis at gmail.com
Thu Dec 31 22:52:52 EET 2020


On 31/12/2020 13:36, Nicolas George wrote:
> This mail is about a project I have to make FFmpeg's API and
> infrastructure more convenient. For a common introduction, see this thread:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2020-December/274167.html
> 
> The way we currently report errors is fine for command-line tools running in
> a terminal, but it does not suit GUI applications at all: they will get a
> generic error, translated into a vague string like "invalid argument", while
> a more precise error message that tells which argument is invalid and how
> will go to the log, and disappear in a black-hole like ~/.xsession-errors or
> even /dev/null; at best, the application will have registered a log callback
> and display the whole log to the user.
> 
> I want to add a new API to return an error all at once, something like this:
> 
>     if (... failure condition...)
>         return av_error_set(ctx, AVERROR_INVALIDDATA,
>                             "Syntax error in file ${file} line ${line}",
>                             "file", finename,
>                             "line", av_d2str(line),
>                             NULL);
> 
> The complete error message will be stored into a pre-allocated AVErrorStatus
> structure in the context, and can be then retrieved by the application
> using:
> 
>     av_error_get(ctx, buf);
> 
> and displayed to the user in any convenient way (dialog box, HTTP response,
> etc.).
> 
> For compatibility, av_log(ctx, ...) will not only print to stderr, but also
> keep the last line(s) of log in the AVErrorStatus buffer in ctx, so that
> code that still does the good old:
> 
>         av_log(ctx, AV_LOG_ERROR, "Syntax error in file %s line %d\n",
>                filename, line);
>         return AVERROR_INVALIDDATA;
> 
> will now work ok with av_error_get().

Finally having proper error support would be very nice; I like this idea a lot.

What I'm a little iffy on is this last part, mostly because a lot of code in
FFmpeg just returns an error without any av_log call, so the current error
buffer in the context will at best be unrelated, or at worst, really misleading
to the user.

Cheers,
- Derek


More information about the ffmpeg-devel mailing list