Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion graphrunner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "graphrunner",
srcs = [
"errors.go",
"graph_runner.go",
"metrics.go",
"native.go",
Expand All @@ -13,6 +14,7 @@ go_library(
deps = [
"//config",
"//core/bazel",
"//core/errors",
"//core/git",
"//core/targethasher",
"//core/workspace",
Expand All @@ -23,11 +25,15 @@ go_library(

go_test(
name = "graphrunner_test",
srcs = ["native_test.go"],
srcs = [
"errors_test.go",
"native_test.go",
],
embed = [":graphrunner"],
deps = [
"//core/bazel",
"//core/bazel/bazelmock",
"//core/errors",
"//core/git/gitmock",
"//core/workspace",
"@com_github_bazelbuild_buildtools//build_proto",
Expand Down
27 changes: 27 additions & 0 deletions graphrunner/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2025 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package graphrunner

import (
"fmt"

tangoerrors "github.com/uber/tango/core/errors"
)

// classifyBazelQueryError classifies any bazel query failure as an infra error.
func classifyBazelQueryError(err error) error {
return tangoerrors.NewInfra(fmt.Errorf("bazel query: %w", err))
}

30 changes: 30 additions & 0 deletions graphrunner/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2025 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package graphrunner

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
tangoerrors "github.com/uber/tango/core/errors"
)

func TestClassifyBazelQueryError(t *testing.T) {
cause := errors.New("some bazel query failure")
err := classifyBazelQueryError(cause)
assert.Equal(t, tangoerrors.ErrorInfra, tangoerrors.GetErrorCode(err))
assert.ErrorIs(t, err, cause)
}
2 changes: 1 addition & 1 deletion graphrunner/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (g *nativeGraphRunner) Compute(ctx context.Context, ws workspace.Workspace)
})
g.emitter.DurationHistogram(_opCompute, "bazel_query_duration", _phaseDurationBuckets).RecordDuration(time.Since(bazelStart))
if err != nil {
return targethasher.EmptyResult(), err
return targethasher.EmptyResult(), classifyBazelQueryError(err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks simple enough to inline ?

return targethasher.Empty, tangoerrors.NewInfra(error.Wrap(err, "baze query fail..."))

}

gitStart := time.Now()
Expand Down
5 changes: 5 additions & 0 deletions orchestrator/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ func classifyLeaseError(err error) error {
}
return tangoerrors.NewInfra(wrappedErr)
}

// classifyBazelClientError classifies any bazel client creation failure as an infra error.
func classifyBazelClientError(err error) error {
return tangoerrors.NewInfra(fmt.Errorf("create bazel client: %w", err))
}
2 changes: 1 addition & 1 deletion orchestrator/native_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (b *nativeOrchestrator) GetTargetGraph(ctx context.Context, req entity.GetT
StreamLogs: repoCfg.StreamBazelLogs,
})
if err != nil {
return nil, fmt.Errorf("create bazel client: %w", err)
return nil, classifyBazelClientError(err)
}
// Use default native graph runner
runner = graphrunner.NewNativeGraphRunner(graphrunner.NativeGraphRunnerParams{
Expand Down