Skip to content

Commit e8b31bc

Browse files
committed
add a sentinel error for later
1 parent 535ca93 commit e8b31bc

4 files changed

Lines changed: 41 additions & 58 deletions

File tree

extension/landprovider/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ go_library(
77
visibility = ["//visibility:public"],
88
deps = ["//entity"],
99
)
10+
11+
exports_files(
12+
["land_provider.go"],
13+
visibility = ["//extension/landprovider/mock:__pkg__"],
14+
)

extension/landprovider/land_provider.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
package landprovider
22

3+
//go:generate mockgen -source=land_provider.go -destination=mock/land_provider_mock.go -package=mock
4+
35
import (
46
"context"
7+
"errors"
8+
"fmt"
59

610
"github.com/uber/submitqueue/entity"
711
)
812

13+
// ErrLandRejected is returned by LandProvider implementations when the land operation
14+
// was attempted but rejected due to the changes themselves (e.g., merge conflict, policy
15+
// violation). This is a terminal failure — retrying will not help.
16+
// Infrastructure errors (network timeout, API unavailable) should be returned as plain
17+
// errors so the consumer can retry.
18+
var ErrLandRejected = errors.New("land rejected")
19+
20+
// IsLandRejected returns true if any error in the error chain is an ErrLandRejected.
21+
func IsLandRejected(err error) bool {
22+
return errors.Is(err, ErrLandRejected)
23+
}
24+
25+
// WrapLandRejected wraps ErrLandRejected with a descriptive reason from the land provider.
26+
func WrapLandRejected(err error) error {
27+
return fmt.Errorf("%w: %w", ErrLandRejected, err)
28+
}
29+
930
// LandEntry pairs a land strategy with the change to land.
1031
// Each entry represents one request's contribution to a batch land operation.
1132
type LandEntry struct {
@@ -22,6 +43,7 @@ type LandProvider interface {
2243
// Land merges the provided changes into the target branch of the given queue.
2344
// The queue identifies the repository and target branch.
2445
// Each entry contains a change and the strategy to use for landing it.
46+
// Returns ErrLandRejected if the land was rejected due to the changes themselves.
2547
Land(ctx context.Context, queue string, entries []LandEntry) (Result, error)
2648
}
2749

extension/landprovider/mock/BUILD.bazel

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
load("@rules_go//extras:gomock.bzl", "gomock")
12
load("@rules_go//go:def.bzl", "go_library")
23

4+
_MOCKGEN = "@org_uber_go_mock//mockgen"
5+
6+
gomock(
7+
name = "mock_land_provider_src",
8+
out = "land_provider_mock.go",
9+
mockgen_tool = _MOCKGEN,
10+
package = "mock",
11+
source = "//extension/landprovider:land_provider.go",
12+
source_importpath = "github.com/uber/submitqueue/extension/landprovider",
13+
)
14+
15+
# gazelle:ignore
316
go_library(
417
name = "mock",
5-
srcs = ["land_provider_mock.go"],
18+
srcs = [":mock_land_provider_src"],
619
importpath = "github.com/uber/submitqueue/extension/landprovider/mock",
720
visibility = ["//visibility:public"],
821
deps = [

extension/landprovider/mock/land_provider_mock.go

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)