Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bigtable: fix error variable shadowing bugs when tracing by named return
Previously in bigtable.(*Table).Apply we started a span and on defer ended with an error that had been previously declared. However, in the body of that function, while in the m.cond == nil scope, we shadowed the original error with: err := gax.Invoke which means that regardless of the result of that newly declared/shadowed "err" error, we would always end the span with a success. An illustration of this problem is: https://play.golang.org/p/1iesjtxGI-e Using a named return parameter ensures that we always capture the finally written error value, regardless of shadowing or a new name at return time. While here I examined a few usages of func <func_name>(ctx context.Context) error { var err error ctx = trace.Startspan(ctx, <span_name>) defer func() { trace.EndSpan(ctx, err) }() and changed them to: func <func_name>(ctx context.Context) (err error) { ctx = trace.Startspan(ctx, <span_name>) defer func() { trace.EndSpan(ctx, err) }() which will prevent the reported problem from creeping back in. Change-Id: I63dd12486844b2fae9d946f895e5c85f80a3a3e1 Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/39651 Reviewed-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Jean de Klerk <deklerk@google.com>
- Loading branch information