Skip to content

[BUG] False positive; return outside scope of Span #25

@cbandy

Description

@cbandy

Describe the bug

When a span is created inside a block (if, for, etc), the record-error check will complain about return statements outside that block.

To Reproduce

Below, the span variable does not exist outside the if block. The return statement does not occur "inside" this span.

package main

import (
  "context"
  "errors"

  "go.opentelemetry.io/otel"
)

func main() {
  run(context.Background())
}

func run(ctx context.Context) error {
  if true {
    _, span := otel.Tracer("foo").Start(ctx, "bar")
    span.End()
  }

  return errors.New("asdf")
}

Expected behavior

I expected no results from the record-error check, as no spans are in scope at the return.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions