This allows the caller to return directly on such an error, with an appropriate errno value. (cherry picked from commit 5898f454)