-
Notifications
You must be signed in to change notification settings - Fork 28
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
refactor(error): remove unnecessary error return #72
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @BlackHole1. Thanks for your PR. I'm waiting for a crc-org member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Thank you. I'll let @cfergeau decide as there might have been reasons, though he is currently on leave. |
Knowing Christophe, this should have been at least a separate commit, but best to make a PR specific to this with clear description. |
/ok-to-test |
If a function does not produce any errors, it should not return an error (except for functions defined by an interface). This will reduce the mental burden on users. Signed-off-by: Black-Hole1 <[email protected]>
1dfca99
to
73eaa96
Compare
Done |
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.
Sorry for the late reviews, you filed these PRs just before I went away for a while :)
I'll need to think some more about the error removal from the *New
changes, there are some plus and minuses to having it/not having it :)
require.NoError(t, err) | ||
vm.AddDevice(dev) | ||
// virtio-net | ||
dev, err = VirtioNetNew("00:11:22:33:44:55") |
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.
This is the main reason why most *New()
methods return an error, some of them require an error return, so for me it's better if they are consistent and all return an error, instead of having to remember it. This also makes the API future-proof if one day we need to return an error.
In most cases, there might be more than one device. Adding the AddDevices method helps reduce the amount of code. Signed-off-by: Black-Hole1 <[email protected]>
73eaa96
to
a7c46b2
Compare
Hey @cfergeau. I agree with what you said: maintaining a consistent style is also a way to reduce cognitive load. In this current PR, I noticed that there are only two
as you said: "This also makes the API future-proof if one day we need to return an error". is also a reason. But for me: The optimal design for now will surely not be optimal in the future, avoid over-design. When the future returns an error, we can consider ways to improve, such as changing the function name to: |
With the recent changes in
Can you also change the |
@@ -18,7 +18,7 @@ func NewVzVirtualMachine(vm *vz.VirtualMachine, config *vz.VirtualMachineConfigu | |||
return &VzVirtualMachine{config: config, VzVM: vm} | |||
} | |||
|
|||
// inspect returns information about the virtual machine like hw resources | |||
// Inspect returns information about the virtual machine like hw resources |
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.
Can you split these comment changes in a separate commit?
For internal/private API, I agree. For external API, changing the API in incompatible ways has to be balanced with the annoyances this will cause to users. And I don't know if there are other users of vfkit's config code. (and API changes get even harder after the module has had a v1 release, as breaking API means we have to change the module path, which causes even more churn to go programs using vfkit) |
@cfergeau Okay, you convinced me. I will close this PR and create two new ones to address the following issues:
|
Sharing our different point of views made for an interesting discussion! Thanks for the 2 additional PRs :) |
If a function does not produce any errors, it should not return an error (except for functions defined by an interface). This will reduce the mental burden on users.
The AddDevices method was also added, on the side.