-
Notifications
You must be signed in to change notification settings - Fork 186
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
docs: most new_handle methods won't return fail #683
Conversation
Fun note, |
oh sorry I forgot to mention, might need to take a look at the Windows version of those. I don't think libuv will be returning an error in the Windows version but not the unix one, but I honestly didn't check the Windows ones. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain that these changes make sense. Although it may be true that the current libuv
implementation of these functions cannot fail, these functions are not defined by libuv
to be unable to fail, and (as noted) the luv
code allows for/handles failure.
For uv_fs_event_init
specifically, it can fail if the platform doesn't support it: https://github.com/libuv/libuv/blob/1479b76310a38d98eda94db2b7f8a40e04b3ff32/src/unix/no-fsevents.c#L27 (used when targeting Haiku, Cygwin, and a few others as far as I can tell).
Yeah you are correct on both of these. It is one of two, either we document the possible failure return and also add an assert or nil check for things like I missed the second one, I will be reverting the changes on |
So to be more specific, this tries to solve the issue of "the examples never seem to check for nil on (be it for the sake of the example) uv.new_pipe even though the return says it can fail, which one is it?" and in my case for an additional "the [LSP annotations] are complaining about a missing nil check for I think for the sake of clearance we can simply remove the possible fail return, and if at any moment libuv decides one of them can fail, we can put it back perhaps? Although frankly it is extremely unlikely that will ever happen in this stable version of libuv for the |
The reservation I have is because |
Hm, that is understandable, didn't think in case of a fork. Would it change much if this change was applied upstream on libuv docs themselves? even though honestly that wouldn't be accepted there either, and it still wouldn't change the fact the ABI will still be compatible with such a fork. I guess for now I will put this aside, it will come haunting me again if I ever start working on the new doc gen, but that is a problem for later (possibly never). |
After diving through the documentation, I see a few things here are actually valid. But in general we can only assume failure is impossible only when explicitly defined by the documentation. Additionally, Luv code itself should mirror these changes, a function that is documented to never fail should not in any case be able to throw an error (ie. the dead path should be removed). All other functions you've described here are following the Libuv guidelines on errors:
Only the following are documented to always succeed:
Everything else has in the past, or may in the future throw an error. |
That is interesting! I just looked at the docs, kind of surprised I will revert the changes on everything except those three for now then! Note: I believe what Truemedian is talking about here is the explicit |
@squeek502 What do you think should be done about the libuv docs's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this, thanks!
Since I've used this docs to generate my luvit-meta definitions, which will complain about not using
assert
on methods that could returnnil
(on failure), I've had to investigate into things likelocal pipe = uv.new_pipe()
not using an assert in the examples.And it appears like it and the methods listed below will never return a failure tuple when initializing a new handle. Even though the docs here explicitly imply otherwise as the return type is
handle_type or fail
.Here are the details and how I came to the conclusion that each one of the methods patched don't return an error:
new_prepare
andnew_check
andnew_idle
:on Luv side:
luv_new_prepare
etc.uv_prepare_init
(anduv_check_init
anduv_idle_init
).ret < 0
.on libuv side:
uv_name_init
methods are defined in loop-watcher.c using a macro.int uv_##name##_init
we see that the return is always0
therefor never fails.The following have been initially included in this PR, they have been reverted now. See the comments below.