Skip to content

Commit

Permalink
[RB] Fix incorrect error exit code (#7758)
Browse files Browse the repository at this point in the history
  • Loading branch information
maggie-lou authored Oct 21, 2024
1 parent 3ffab9c commit 3c39ae1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cli/remotebazel/remotebazel.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ func Run(ctx context.Context, opts RunOpts, repoConfig *RepoConfig) (int, error)

conn, err := grpc_client.DialSimple(opts.Server)
if err != nil {
return 0, status.UnavailableErrorf("could not connect to BuildBuddy remote bazel service %q: %s", opts.Server, err)
return 1, status.UnavailableErrorf("could not connect to BuildBuddy remote bazel service %q: %s", opts.Server, err)
}
bbClient := bbspb.NewBuildBuddyServiceClient(conn)

Expand Down Expand Up @@ -771,7 +771,7 @@ func Run(ctx context.Context, opts RunOpts, repoConfig *RepoConfig) (int, error)

platform, err := rexec.MakePlatform(*execPropsFlag...)
if err != nil {
return 0, status.InvalidArgumentErrorf("invalid exec properties - key value pairs must be separated by '=': %s", err)
return 1, status.InvalidArgumentErrorf("invalid exec properties - key value pairs must be separated by '=': %s", err)
}

req := &rnpb.RunRequest{
Expand Down Expand Up @@ -819,7 +819,7 @@ func Run(ctx context.Context, opts RunOpts, repoConfig *RepoConfig) (int, error)
log.Printf("\nWaiting for available remote runner...\n")
rsp, err := bbClient.Run(ctx, req)
if err != nil {
return 0, status.UnknownErrorf("error running bazel: %s", err)
return 1, status.UnknownErrorf("error running bazel: %s", err)
}

iid := rsp.GetInvocationId()
Expand Down Expand Up @@ -847,11 +847,11 @@ func Run(ctx context.Context, opts RunOpts, repoConfig *RepoConfig) (int, error)
interactive := terminal.IsTTY(os.Stdin) && terminal.IsTTY(os.Stderr)
if interactive {
if err := streamLogs(ctx, bbClient, iid); err != nil {
return 0, status.WrapError(err, "streaming logs")
return 1, status.WrapError(err, "streaming logs")
}
} else {
if err := printLogs(ctx, bbClient, iid); err != nil {
return 0, status.WrapError(err, "streaming logs")
return 1, status.WrapError(err, "streaming logs")
}
}
isInvocationRunning = false
Expand Down Expand Up @@ -885,7 +885,7 @@ func Run(ctx context.Context, opts RunOpts, repoConfig *RepoConfig) (int, error)
})
err = eg.Wait()
if err != nil {
return 0, err
return 1, err
}

childIID := ""
Expand All @@ -912,28 +912,28 @@ func Run(ctx context.Context, opts RunOpts, repoConfig *RepoConfig) (int, error)
if childIID != "" {
conn, err := grpc_client.DialSimple(opts.Server)
if err != nil {
return 0, fmt.Errorf("could not communicate with sidecar: %s", err)
return 1, fmt.Errorf("could not communicate with sidecar: %s", err)
}
env.SetByteStreamClient(bspb.NewByteStreamClient(conn))
env.SetContentAddressableStorageClient(repb.NewContentAddressableStorageClient(conn))
ctx = metadata.AppendToOutgoingContext(ctx, "x-buildbuddy-api-key", opts.APIKey)

mainOutputs, err := lookupBazelInvocationOutputs(ctx, bbClient, childIID)
if err != nil {
return 0, err
return 1, err
}
outputsBaseDir := filepath.Dir(opts.WorkspaceFilePath)
outputs, err := downloadOutputs(ctx, env, mainOutputs, runfiles, runfileDirectories, outputsBaseDir)
if err != nil {
return 0, err
return 1, err
}
if runOutput {
if len(outputs) > 1 {
return 0, fmt.Errorf("run requested but target produced more than one artifact")
return 1, fmt.Errorf("run requested but target produced more than one artifact")
}
binPath := outputs[0]
if err := os.Chmod(binPath, 0755); err != nil {
return 0, fmt.Errorf("could not prepare binary %q for execution: %s", binPath, err)
return 1, fmt.Errorf("could not prepare binary %q for execution: %s", binPath, err)
}
execArgs := defaultRunArgs
// Pass through extra arguments (-- --foo=bar) from the command line.
Expand All @@ -947,7 +947,7 @@ func Run(ctx context.Context, opts RunOpts, repoConfig *RepoConfig) (int, error)
if e, ok := err.(*exec.ExitError); ok {
return e.ExitCode(), nil
}
return 0, err
return 1, err
}
} else {
log.Warnf("Cannot download outputs - no child invocations found")
Expand Down

0 comments on commit 3c39ae1

Please sign in to comment.