bazelbuild / bazelbuild/bazel

Bazel cquery ignores starlark:expr failures, produces zero-exit status.

Open
#21,466 4 comments 2 reactions 0 assignees View on GitHub
P3 team-Configurability type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

When evaluating custom expressions using `bazel cquery --output=starlark`, failures occurring during the evaluation of the custom starlark do not cause the command to report a non-zero status. A non-zero exit status is useful to scripts and automation for distinguishing between a failed execution and a successful execution that simply produced an empty output.

### Which category does this issue belong to?

_No response_

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

```sh
git clone https://github.com/bazelbuild/bazel.git
cd bazel/examples/cpp

# A query that contains errors.
bazel cquery --output=starlark --starlark:expr='target.no_such_attribute' :all
echo $? # Status is zero.

# A query that explicitly fails.
bazel cquery --output=starlark --starlark:expr='fail("Explicit failure")' :all
echo $? # Also zero.
```

### Which operating system are you running Bazel on?

macOS 14.3

### What is the output of `bazel info release`?

release 7.0.2

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

_No response_

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

First reported in Bazel Slack: https://bazelbuild.slack.com/archives/CA31HN1T3/p1708474534459849

Contributor guide

Open the contributing guide

Research direction

Start by running the two provided bazel cquery commands with --output=starlark and --starlark:expr, then trace custom Starlark expression evaluation and how cquery propagates failures to its process exit status. Done means both a missing attribute and fail("Explicit failure") produce a non-zero exit status while successful empty output remains distinguishable.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.