Skip to content

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

@plobsing

Description

@plobsing

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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3We're not considering working on this, but happy to review a PR. (No assignee)team-Configurabilityplatforms, toolchains, cquery, select(), config transitionstype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions