Skip to content
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

false negative for direct returns inside wrapper functions #55

Open
cwrau opened this issue Oct 2, 2024 · 0 comments
Open

false negative for direct returns inside wrapper functions #55

cwrau opened this issue Oct 2, 2024 · 0 comments

Comments

@cwrau
Copy link

cwrau commented Oct 2, 2024

The following functions;

func (s *Service) ListLoadBalancers3(ctx context.Context) ([]loadbalancers.LoadBalancer, error) {
	return util.WithSpan(ctx, s.loadBalancerClient.TracerName, "ListLoadBalancers",
		func(ctx context.Context, span trace.Span) ([]loadbalancers.LoadBalancer, error) {
			return cloudUtil.GetItems(ctx, s.loadBalancerClient.ServiceClient,
				loadbalancers.ListOptsBuilder(
					loadbalancers.ListOpts{},
				),
				loadbalancers.List,
				loadbalancers.ExtractLoadBalancers,
			)
		},
	)
}

func (s *Service) ListLoadBalancers4(ctx context.Context) ([]loadbalancers.LoadBalancer, error) {
	return cloudUtil.GetItems(ctx, s.loadBalancerClient.ServiceClient,
		loadbalancers.ListOptsBuilder(
			loadbalancers.ListOpts{},
		),
		loadbalancers.List,
		loadbalancers.ExtractLoadBalancers,
	)
}

have different linting errors, the upper one only reports on util.withSpan and not on cloudUtil.GetItems while the lower one correctly identifies cloudUtil.GetItems.

If I ignore util.withSpan the error vanishes, but there is still no report on cloudUtil.getItems.

If I do the following;

func (s *Service) ListLoadBalancers2(ctx context.Context) ([]loadbalancers.LoadBalancer, error) {
	return util.WithSpan(ctx, s.loadBalancerClient.TracerName, "ListLoadBalancers",
		func(ctx context.Context, span trace.Span) ([]loadbalancers.LoadBalancer, error) {
			loadBalancers, err := cloudUtil.GetItems(ctx, s.loadBalancerClient.ServiceClient,
				loadbalancers.ListOptsBuilder(
					loadbalancers.ListOpts{},
				),
				loadbalancers.List,
				loadbalancers.ExtractLoadBalancers,
			)
			if err != nil {
				return nil, err
			}
			return loadBalancers, nil
		},
	)
}

or

func (s *Service) ListLoadBalancers2(ctx context.Context) ([]loadbalancers.LoadBalancer, error) {
	return util.WithSpan(ctx, s.loadBalancerClient.TracerName, "ListLoadBalancers",
		func(ctx context.Context, span trace.Span) ([]loadbalancers.LoadBalancer, error) {
			loadBalancers, err := cloudUtil.GetItems(ctx, s.loadBalancerClient.ServiceClient,
				loadbalancers.ListOptsBuilder(
					loadbalancers.ListOpts{},
				),
				loadbalancers.List,
				loadbalancers.ExtractLoadBalancers,
			)
			return loadBalancers, err
		},
	)
}

the linter correctly identifies the return nil, err via cloudUtil.GetItems.

So seemingly "direct returns" or whatever this is called are not being detected if it is inside an (ignored) wrapper function.

As nearly all my functions use wrapper functions, for tracing, this is quite the problem.

Is there a setting I need to set or is this a bug?

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

No branches or pull requests

1 participant