Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling when Mediainfo is not able to open a file #988

Open
plondino opened this issue Dec 6, 2024 · 4 comments
Open

Error handling when Mediainfo is not able to open a file #988

plondino opened this issue Dec 6, 2024 · 4 comments
Assignees

Comments

@plondino
Copy link

plondino commented Dec 6, 2024

If Mediainfo can't open a file for any reason, it just returns no output. This makes troubleshooting difficult - currently I am trying to figure out why a presigned URL returns no output for Mediainfo even though I can wget the first 2M bytes at that same URL. Testing locally, a file that doesn't exist and a file with no read permissions return the same lack of an error.

Is it possible to:

  • Return a nonzero error code for failing to open the input file
  • Output the failure reason to stderr or stdout

In the short term, is there any debugging mode that can shed light on the internal failure? The --Details=1 flag doesn't appear to add any additional output if the file is not accessible.

@plondino
Copy link
Author

plondino commented Dec 7, 2024

It does seem that curl errors are actually displayed:

E: https://bucket.s3.amazonaws.com/media.mov, error setting certificate verify locations:
  CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none

However since I was using the Python wrapper around the binary (https://github.com/MediaArea/MediaInfoLib/blob/master/Source/MediaInfoDLL/MediaInfoDLL3.py) it wasn't output anywhere - I will look into this to see if it's possible to capture stdout.

The return code should still probably not be 0 on a file opening error.

@JeromeMartinez JeromeMartinez self-assigned this Dec 13, 2024
@JeromeMartinez
Copy link
Member

If Mediainfo can't open a file for any reason, it just returns no output. This makes troubleshooting difficult

It was definitely a big design mistake... 25 years ago :(.

Is it possible to:
Return a nonzero error code for failing to open the input file

Currently it is 1 if OK, else 0. Changing that would break the API, I am reluctant to do that now.

In the short term, is there any debugging mode that can shed light on the internal failure?

No with Python :(.

It does seem that curl errors are actually displayed:

We have a callback function in the CLI for the errors but it is not available with Python :(.

What I imagine without changing the API is to have an option for getting the error log, so you can access it from Python.

@plondino
Copy link
Author

plondino commented Jan 7, 2025

Currently it is 1 if OK, else 0. Changing that would break the API, I am reluctant to do that now.

Do you mean that the C function returns 1 (true) for success or 0 (false) for failure? That seems ok, but it seems like the return code to the OS should be 0 on success and non-zero on a failure. The behavior currently seems to always be 0 whether the file was read successfully or not, so that running in a bash script doesn't distinguish between failure or success.

What I imagine without changing the API is to have an option for getting the error log, so you can access it from Python.

This would allow me to check if there were errors and capture the error message? That seems like exactly what I need.

@JeromeMartinez
Copy link
Member

The behavior currently seems to always be 0 whether the file was read successfully or not, so that running in a bash script doesn't distinguish between failure or success.

I was speaking about the API, not the CLI. It was not seriously handled 20 years ago when I started MediaInfo and it definitely need some coherency and cleanup :(.

This would allow me to check if there were errors and capture the error message? That seems like exactly what I need.

Yes. Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants