bazelbuild / bazel-watcher

Tools for building Bazel targets when source files change.
Apache License 2.0
440 stars 116 forks source link

Bazel query failed: exit status 7 #641

Closed vorburger closed 7 months ago

vorburger commented 9 months ago

Describe the bug Bazel Watcher seems to be broken for https://github.com/enola-dev/enola.

The root cause appears to be something about Error querying for source files: exit status 7.

Reproduction instructions Steps to reproduce the behavior:

  1. git clone https://github.com/enola-dev/enola
  2. cd enola
  3. git checkout c87a80e027852d31ad4219813d281d9bede1c6b2
  4. ibazel test //...
  5. Edit //common/common/src/main/java/dev/enola/common/io/resource/FileResource.java to have a smiley face at the top
  6. See error

Expected behavior It should fail to build the Java file with the smiley face at the top? 🤣

Actual behavior Nothing, the change is ignored. It's because of these errors at start-up:

ibazel test //...
WARNING: no ibazel version found in your node_modules.
        We recommend installing a devDependency on ibazel so you use the same
        version as other engineers on this project.
        Using the globally installed version at /home/vorburger/.npm/lib/node_modules/@bazel/ibazel
iBazel [12:55PM]: Querying for files to watch...
iBazel [12:55PM]: Bazel query failed: exit status 7
iBazel [12:55PM]: Error querying for source files: exit status 7
iBazel [12:55PM]: Bazel query failed: exit status 7
iBazel [12:55PM]: Error querying for source files: exit status 7
iBazel [12:55PM]: Testing //...
Loading:
Loading:
Loading: 0 packages loaded
Analyzing: 74 targets (0 packages loaded, 0 targets configured)
Analyzing: 74 targets (50 packages loaded, 31 targets configured)
    Fetching repository @local_jdk; starting
    Fetching repository @rules_java~5.5.1~toolchains~local_jdk; starting
Analyzing: 74 targets (53 packages loaded, 393 targets configured)
    currently loading: @rules_go~0.44.1//go/toolchain
Analyzing: 74 targets (81 packages loaded, 7035 targets configured)
    currently loading: @rules_jvm_external~5.3~maven~io_perfmark_perfmark_api_\
0_25_0//file ... (11 packages)
Analyzing: 74 targets (264 packages loaded, 11167 targets configured)
    Fetching ...l_tools~xcode_configure_extension~local_config_xcode; starting
Analyzing: 74 targets (265 packages loaded, 11311 targets configured)
INFO: Analyzed 74 targets (313 packages loaded, 13495 targets configured).
 checking cached actions
INFO: Found 74 targets...
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions
 checking cached actions

INFO: Elapsed time: 3.491s, Critical Path: 0.00s
 checking cached actions
INFO: 0 processes.
 checking cached actions
INFO: Build completed successfully, 0 total actions
iBazel [12:55PM]: Found a single target test. Streaming results. You can override this by explicitly passing --test_output=summary
WARNING: Streamed test output requested. All tests will be run locally, without sharding, one at a time
INFO: Analyzed 74 targets (0 packages loaded, 554 targets configured).
INFO: Found 30 targets and 44 test targets...
INFO: Elapsed time: 4.275s, Critical Path: 1.45s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
//cli:src/test/java/dev/enola/cli/ClasspathHellDuplicatesCheckerTest (cached) PASSED in 2.8s
//cli:src/test/java/dev/enola/cli/EnolaTest                     (cached) PASSED in 18.4s
//cli:src/test/java/dev/enola/cli/SystemOutErrCaptureTest       (cached) PASSED in 2.0s
//common/common:src/test/java/dev/enola/common/io/mediatype/MediaTypeDetectorTest (cached) PASSED in 2.0s
//common/common:src/test/java/dev/enola/common/io/mediatype/MediaTypesTest (cached) PASSED in 1.4s
//common/common:src/test/java/dev/enola/common/io/resource/ClasspathUrlResourceTest (cached) PASSED in 1.9s
//common/common:src/test/java/dev/enola/common/io/resource/EmptyResourceTest (cached) PASSED in 1.7s
//common/common:src/test/java/dev/enola/common/io/resource/ErrorResourceTest (cached) PASSED in 1.7s
//common/common:src/test/java/dev/enola/common/io/resource/FileDescriptorResourceTest (cached) PASSED in 1.8s
//common/common:src/test/java/dev/enola/common/io/resource/FileResourceTest (cached) PASSED in 1.9s
//common/common:src/test/java/dev/enola/common/io/resource/HttpUrlResourceTest (cached) PASSED in 1.2s
//common/common:src/test/java/dev/enola/common/io/resource/MemoryResourceTest (cached) PASSED in 1.4s
//common/common:src/test/java/dev/enola/common/io/resource/NullResourceTest (cached) PASSED in 1.3s
//common/common:src/test/java/dev/enola/common/io/resource/ReplacingResourceTest (cached) PASSED in 1.6s
//common/common:src/test/java/dev/enola/common/io/resource/ResourceProvidersTest (cached) PASSED in 1.7s
//common/common:src/test/java/dev/enola/common/io/resource/StringResourceTest (cached) PASSED in 1.4s
//common/common:src/test/java/dev/enola/common/io/resource/URIsTest (cached) PASSED in 1.6s
//common/common:src/test/java/dev/enola/common/protobuf/ProtobufMediaTypesTest (cached) PASSED in 1.7s
//common/markdown:src/test/java/dev/enola/common/markdown/exec/ExecMDTest (cached) PASSED in 2.2s
//common/markdown:src/test/java/dev/enola/common/markdown/exec/RunnerTest (cached) PASSED in 2.4s
//common/protobuf:src/test/java/dev/enola/common/protobuf/MessageValidatorTest (cached) PASSED in 1.6s
//common/protobuf:src/test/java/dev/enola/common/protobuf/ProtoIOTest (cached) PASSED in 2.9s
//common/yamljson:src/test/java/dev/enola/common/yamljson/YamlJsonTest (cached) PASSED in 2.6s
//connectors/demo:src/test/java/dev/enola/demo/ServerTest       (cached) PASSED in 6.0s
//core/impl:src/test/java/dev/enola/core/EntityServiceProviderTest (cached) PASSED in 6.3s
//core/impl:src/test/java/dev/enola/core/EntityTest             (cached) PASSED in 3.3s
//core/impl:src/test/java/dev/enola/core/grpc/EnolaGrpcServerTest (cached) PASSED in 5.9s
//core/impl:src/test/java/dev/enola/core/iri/URITemplateMatcherChainTest (cached) PASSED in 1.6s
//core/impl:src/test/java/dev/enola/core/iri/URITemplatePatternizerTest (cached) PASSED in 1.5s
//core/impl:src/test/java/dev/enola/core/iri/URITemplateTest    (cached) PASSED in 1.9s
//core/impl:src/test/java/dev/enola/core/meta/EntityKindRepositoryTest (cached) PASSED in 4.1s
//core/impl:src/test/java/dev/enola/core/meta/EntityKindValidationsTest (cached) PASSED in 3.6s
//core/impl:src/test/java/dev/enola/core/meta/SchemaAspectTest  (cached) PASSED in 3.2s
//core/impl:src/test/java/dev/enola/core/meta/TypeRegistryWrapperTest (cached) PASSED in 3.2s
//core/impl:src/test/java/dev/enola/core/meta/docgen/MarkdownDocGeneratorTest (cached) PASSED in 2.8s
//core/impl:src/test/java/dev/enola/core/meta/docgen/StringUtilTest (cached) PASSED in 1.7s
//core/impl:src/test/java/dev/enola/core/tbd/RosettaTest        (cached) PASSED in 2.8s
//core/lib:core_buf_proto_lint                                  (cached) PASSED in 0.0s
//core/lib:src/test/java/dev/enola/core/ERITest                 (cached) PASSED in 0.7s
//core/lib:src/test/java/dev/enola/core/IDsTest                 (cached) PASSED in 1.0s
//web/rest:src/test/java/dev/enola/web/rest/RestTest            (cached) PASSED in 6.3s
//web/sun:src/test/java/dev/enola/web/sun/test/SunServerTest    (cached) PASSED in 5.4s
//web/ui-soy:src/test/java/dev/enola/web/ui/SoyTest             (cached) PASSED in 4.2s
//web/ui-soy:src/test/java/dev/enola/web/ui/UiTest              (cached) PASSED in 10.8s

Executed 0 out of 44 tests: 44 tests pass.

################################################################################
# Did you know iBazel can invoke programs like Gazelle, buildozer, and         #
# other BUILD file generators for you automatically based on bazel output?     #
# Documentation at: https://github.com/bazelbuild/bazel-watcher#output-runner  #
################################################################################

bazel query --output=build //path/to:target If your issue is about a specific target in your system working, Please include the output of bazel query --output=build //path/to:target,

$ bazel query --output=build //...
...

see https://gist.github.com/vorburger/8868ecae9418d8bfe16cdeb9c3bcbbb9

Version (please complete the following information):

Additional context It also seems weird (to me) that those Bazel query failed problems don't cause ibazel to "give up" and fail with a non-0 exit code. But let's keep this issue for fixing this specific actual problem - I'll file another issue for the general "exit if Bazel query failed fatally (exit status 7)".

achew22 commented 9 months ago

What happens when you run bazel query //...?

vorburger commented 9 months ago

What happens when you run bazel query //...?

@achew22 this happens, as far as I can tell that works just fine:

$ bazel query //...

//cli:enola
//cli:src/test/java/dev/enola/cli/ClasspathHellDuplicatesCheckerTest
//cli:src/test/java/dev/enola/cli/EnolaTest
//cli:src/test/java/dev/enola/cli/SystemOutErrCaptureTest
//common/common:common
//common/common:src/test/java/dev/enola/common/io/mediatype/MediaTypeDetectorTest
//common/common:src/test/java/dev/enola/common/io/mediatype/MediaTypesTest
//common/common:src/test/java/dev/enola/common/io/resource/ClasspathUrlResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/EmptyResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/ErrorResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/FileDescriptorResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/FileResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/HttpUrlResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/MemoryResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/NullResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/ReplacingResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/ResourceProvidersTest
//common/common:src/test/java/dev/enola/common/io/resource/StringResourceTest
//common/common:src/test/java/dev/enola/common/io/resource/URIsTest
//common/common:src/test/java/dev/enola/common/protobuf/ProtobufMediaTypesTest
//common/markdown:markdown
//common/markdown:src/test/java/dev/enola/common/markdown/exec/ExecMDTest
//common/markdown:src/test/java/dev/enola/common/markdown/exec/RunnerTest
//common/protobuf:protobuf
//common/protobuf:src/test/java/dev/enola/common/protobuf/MessageValidatorTest
//common/protobuf:src/test/java/dev/enola/common/protobuf/ProtoIOTest
//common/protobuf:validation_proto
//common/protobuf:validation_proto_java_library
//common/yamljson:src/test/java/dev/enola/common/yamljson/YamlJsonTest
//common/yamljson:yamljson
//connectors/demo:demo
//connectors/demo:demo_java_proto
//connectors/demo:demo_proto
//connectors/demo:src/test/java/dev/enola/demo/ServerTest
//connectors/k8s:enola-k8s
//core/impl:impl
//core/impl:src/test/java/dev/enola/core/EntityServiceProviderTest
//core/impl:src/test/java/dev/enola/core/EntityTest
//core/impl:src/test/java/dev/enola/core/grpc/EnolaGrpcServerTest
//core/impl:src/test/java/dev/enola/core/iri/URITemplateMatcherChainTest
//core/impl:src/test/java/dev/enola/core/iri/URITemplatePatternizerTest
//core/impl:src/test/java/dev/enola/core/iri/URITemplateTest
//core/impl:src/test/java/dev/enola/core/meta/EntityKindRepositoryTest
//core/impl:src/test/java/dev/enola/core/meta/EntityKindValidationsTest
//core/impl:src/test/java/dev/enola/core/meta/SchemaAspectTest
//core/impl:src/test/java/dev/enola/core/meta/TypeRegistryWrapperTest
//core/impl:src/test/java/dev/enola/core/meta/docgen/MarkdownDocGeneratorTest
//core/impl:src/test/java/dev/enola/core/meta/docgen/StringUtilTest
//core/impl:src/test/java/dev/enola/core/tbd/RosettaTest
//core/lib:connector_go_proto
//core/lib:connector_java_grpc
//core/lib:connector_proto
//core/lib:core_buf_proto_lint
//core/lib:core_go_proto
//core/lib:core_java_grpc
//core/lib:core_java_proto
//core/lib:core_proto
//core/lib:core_proto_doc
//core/lib:lib_java
//core/lib:meta_go_proto
//core/lib:meta_proto
//core/lib:src/test/java/dev/enola/core/ERITest
//core/lib:src/test/java/dev/enola/core/IDsTest
//core/lib:util_go_proto
//core/lib:util_proto
//tools/hello:hello
//web/api:api
//web/rest:rest
//web/rest:src/test/java/dev/enola/web/rest/RestTest
//web/sun:src/test/java/dev/enola/web/sun/test/SunServerTest
//web/sun:sun
//web/ui-soy:src/test/java/dev/enola/web/ui/SoyTest
//web/ui-soy:src/test/java/dev/enola/web/ui/UiTest
//web/ui-soy:ui-soy
Loading: 0 packages loaded

NB also, as above, just to make sure it wasn't overlooked:

$ bazel query --output=build //...
...

see https://gist.github.com/vorburger/8868ecae9418d8bfe16cdeb9c3bcbbb9

achew22 commented 9 months ago

Yeah, I took a look at the link and misread it. You had a code fence, ``, at the bottom which I misinterpreted as a...` thinking you'd truncated the results.

Next up is to run a couple more queries and see where it failed.

bazel query "kind('source file', deps(set(//...)))"

and

bazel query "buildfiles(deps(set(//...)))"

If those don't break then I'm officially perplexed and we'll need to build a patched binary with more debugging to figure out what's going on. Not sure what kind of patch yet, but a thing to be aware of

vorburger commented 9 months ago

As suggested above:

$ git clone https://github.com/enola-dev/enola.git && cd enola
$ git checkout 5383cf9
$ bazelisk query "kind('source file', deps(set(//...)))"

Starting local Bazel server and connecting to it...
INFO: Repository bazel_tools~remote_coverage_tools_extension~remote_coverage_tools instantiated at:
  callstack not available
Repository rule http_archive defined at:
  /home/vorburger/.cache/bazel/_bazel_vorburger/a3cf8df34f0c7a76e9926daaad9ffbf4/external/bazel_tools/tools/build_defs/repo/http.bzl:372:31: in <toplevel>
INFO: Repository rules_license~0.0.7 instantiated at:
  callstack not available
Repository rule http_archive defined at:
  /home/vorburger/.cache/bazel/_bazel_vorburger/a3cf8df34f0c7a76e9926daaad9ffbf4/external/bazel_tools/tools/build_defs/repo/http.bzl:372:31: in <toplevel>
INFO: Repository protoc_gen_buf_lint_darwin_x86_64 instantiated at:
  /home/vorburger/git/github.com/enola-dev/enola/WORKSPACE.bazel:70:27: in <toplevel>
  /home/vorburger/.cache/bazel/_bazel_vorburger/a3cf8df34f0c7a76e9926daaad9ffbf4/external/rules_proto_grpc/buf/repositories.bzl:20:38: in buf_repos
  /home/vorburger/.cache/bazel/_bazel_vorburger/a3cf8df34f0c7a76e9926daaad9ffbf4/external/rules_proto_grpc/repositories.bzl:527:24: in protoc_gen_buf_lint_darwin_x86_64
  /home/vorburger/.cache/bazel/_bazel_vorburger/a3cf8df34f0c7a76e9926daaad9ffbf4/external/rules_proto_grpc/repositories.bzl:409:22: in _generic_dependency
Repository rule http_file defined at:
  /home/vorburger/.cache/bazel/_bazel_vorburger/a3cf8df34f0c7a76e9926daaad9ffbf4/external/bazel_tools/tools/build_defs/repo/http.bzl:466:28: in <toplevel>
ERROR: Evaluation of subquery "deps(set(//...))" failed (did you want to use --keep_going?): preloading transitive closure failed: no such package '@com_google_protobuf_javalite//': The repository '@com_google_protobuf_javalite' could not be resolved: Repository '@com_google_protobuf_javalite' is not defined
Loading: 61 packages loaded
    currently loading: @bazel_tools//third_party/zlib
    Fetching https://mirror.bazel.build/bazel_coverage_output_generator/releases/coverage_output_generator-v2.6.zip
    Fetching https://github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz
    Fetching https://github.com/bufbuild/buf/releases/download/v1.9.0/protoc-gen-buf-lint-Darwin-x86_64

as well as:

$ bazelisk query "buildfiles(deps(set(//...)))"
INFO: Repository bazel_tools~remote_coverage_tools_extension~remote_coverage_tools instantiated at:
  callstack not available
Repository rule http_archive defined at:
  /home/vorburger/.cache/bazel/_bazel_vorburger/a3cf8df34f0c7a76e9926daaad9ffbf4/external/bazel_tools/tools/build_defs/repo/http.bzl:372:31: in <toplevel>
ERROR: Evaluation of subquery "deps(set(//...))" failed (did you want to use --keep_going?): preloading transitive closure failed: no such package '@com_google_protobuf_javalite//': The repository '@com_google_protobuf_javalite' could not be resolved: Repository '@com_google_protobuf_javalite' is not defined
Loading: 7 packages loaded
    Fetching https://mirror.bazel.build/bazel_coverage_output_generator/releases/coverage_output_generator-v2.6.zip

Aha! I may have a bit of a mess around this in my project, so this helps me to dig in more (some other day, not now); it's something related to:

ERROR: Evaluation of subquery "deps(set(//...))" failed (did you want to use --keep_going?): preloading transitive closure failed: no such package '@com_google_protobuf_javalite//': The repository '@com_google_protobuf_javalite' could not be resolved: Repository '@com_google_protobuf_javalite' is not defined

binary with more debugging to figure out what's going on. Not sure what kind of patch yet, but a thing to be aware of

Yeah, so perhaps ibazel could be improved to not "swallow" this (above) kind of failures, and show them to a user, and exit? How would you like to proceed? I'm happy to close this issue, as a "problem in my project and not ibazel", now that it's clearer - and perhaps you can use #642 about such an enhancement?

BTW it's also slightly strange to me as a user that I can build the project without the problem (above), but need to fix it to be able to use the watcher - but that's probably due to design details which are much harder to change, and it needs this.

github-actions[bot] commented 7 months ago

Stale issue message