Skip to content

Conversation

ashwat287
Copy link
Contributor

fixes #3875

@ashwat287 ashwat287 force-pushed the RefactorContextBG branch 3 times, most recently from d321bbf to 1566004 Compare August 21, 2025 17:59
@@ -71,7 +71,7 @@ func cloneAction(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
yBytes, err := yqutil.EvaluateExpression(yq, yContent)
yBytes, err := yqutil.EvaluateExpression(cmd.Context(), yq, yContent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
yBytes, err := yqutil.EvaluateExpression(cmd.Context(), yq, yContent)
yBytes, err := yqutil.EvaluateExpression(ctx, yq, yContent)

Same for other occurrences of cmd.Context() too

jandubois
jandubois previously approved these changes Aug 23, 2025
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

I have only 2 stylistic nit-picks that you can address, if you want. But we already have existing functions that use _ for the single unnamed parameter, so it isn't a new issue.

There is of course the issue of failing CI, but I think this might be GitHub flakiness; we'll see...

@@ -63,7 +63,7 @@ type Registration interface {
// GuestAgent defines operations for the guest agent.
type GuestAgent interface {
// ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
ForwardGuestAgent() bool
ForwardGuestAgent(_ context.Context) bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a function/method has only unnamed parameters, then you don't need to specify the _ name. It is only needed when you want to provide a name for parameters with a basic type like bool. int, or string, which are not self-explanatory because you cannot mix named and unnamed parameters.

Suggested change
ForwardGuestAgent(_ context.Context) bool
ForwardGuestAgent(context.Context) bool

Copy link
Contributor Author

@ashwat287 ashwat287 Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we raise a new Issue/PR focusing on removing _ for single unnamed parameter to make it consistent?

@@ -585,19 +585,20 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
remoteUnix := "/run/lima-guestagent.sock"

a.onClose = append(a.onClose, func() error {
ctxBG := context.Background()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a premature optimization. You introduce an extra variable name that the user needs to keep track of instead of calling a very cheap function multiple times.

It doesn't matter much, but I would always try to minimize the context that the developer needs to carry in their head while reading the code, especially if it is a rather long function.

Copy link
Contributor Author

@ashwat287 ashwat287 Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense—I'll drop ctxBG and just call context.Background() directly.

Signed-off-by: ashwat287 <ashwatpas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce context.Background()
3 participants