alsa: Treat -22 (EINVAL) as an expected error #252
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! 👋
While testing this library on Linux (x86_64, Ubuntu 18.04, Alsa k4.15.0-43-generic) I found that the enumerate example panics with the following stacktrace:
I believe this is caused by this call to the ALSA API returning
-22(EINVAL) for a dmix playback device when it is opened withalsa::SND_PCM_STREAM_CAPTURE.(It likely also returns the same for a capture device opened with
alsa::SND_PCM_STREAM_PLAYBACKbut I haven't confirmed yet.)I believe that the library shouldn't generate a panic in this case. I've attached a PR with a simple fix. My questions are:
EINVALas an expected error here? In other words, are there other ways to make Alsa return this value which we wouldn't necessarily expect to be handled like this?🙏