You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[RFC] Rust: A fallible from_kernel_errno with Result<Error> return
Currently, from_kernel_errno is an infallible function acting as a
constructor for Error. In order to achieve its type invariant, We add
a check in it which will prompt a warning and return Error::EINVL when
errno given is invalid.
While this approach ensures type invariant, it brings great
ambiguities. When Error::EINVL is returned, the caller has no way to
recognize whether it is a valid errno coming from the kernel or an
error issued by the check. This tricky behavior may confuse developers
and introduce subtle bugs. Since Error will be used in all respects of
the kernel, It's definitely not a sound solution.
This RFC proposes that we make from_kernel_errno return a
Result<Error>. Thus, we have an explicit, clear, and fallible version
of from_kernel_errno by which callers are able to know what really
happened behind the scene. And it also provides certain flexibility.
We pass the power to callers, they can decide how to deal with invalid
`errno` case by case.
Signed-off-by: Fox Chen <[email protected]>
0 commit comments