[RFC] A fallible from_kernel_errno with Result<Error> return #347
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.
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 returnError::EINVL
whenerrno
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 validerrno
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 nota sound solution.
This RFC proposes that we make
from_kernel_errno()
return aResult<Error>
. Thus, we have an explicit, clear, and fallible version offrom_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 invaliderrno
case by case.Note:
errno
(e.g.EBUG
orEIKE
). This is also viable, however: 1) it needs interaction with upstream 2)from_kernel_errno
is still an infallible function that can fail.Reference:
#324 #283
May influence:
#335