diff --git a/graphrunner/BUILD.bazel b/graphrunner/BUILD.bazel index 99f8b0a..3170700 100644 --- a/graphrunner/BUILD.bazel +++ b/graphrunner/BUILD.bazel @@ -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", @@ -13,6 +14,7 @@ go_library( deps = [ "//config", "//core/bazel", + "//core/errors", "//core/git", "//core/targethasher", "//core/workspace", @@ -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", diff --git a/graphrunner/errors.go b/graphrunner/errors.go new file mode 100644 index 0000000..bc33d14 --- /dev/null +++ b/graphrunner/errors.go @@ -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)) +} + diff --git a/graphrunner/errors_test.go b/graphrunner/errors_test.go new file mode 100644 index 0000000..7e7c9ef --- /dev/null +++ b/graphrunner/errors_test.go @@ -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) +} diff --git a/graphrunner/native.go b/graphrunner/native.go index 50f3a1f..3b2fad7 100644 --- a/graphrunner/native.go +++ b/graphrunner/native.go @@ -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) } gitStart := time.Now() diff --git a/orchestrator/errors.go b/orchestrator/errors.go index 1a42294..f41c494 100644 --- a/orchestrator/errors.go +++ b/orchestrator/errors.go @@ -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)) +} diff --git a/orchestrator/native_orchestrator.go b/orchestrator/native_orchestrator.go index 26d744c..3d77bb2 100644 --- a/orchestrator/native_orchestrator.go +++ b/orchestrator/native_orchestrator.go @@ -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{