bazelbuild / bazelbuild/bazel

Error Message Could be Improved for `http_file`

Open
#16,375 8 comments 0 reactions 0 assignees View on GitHub
bad error messaging good first issue help wanted P3 team-ExternalDeps type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the issue

The error messages when referencing an `http_file` in the `srcs` section can be cryptic and could be improved to help the user fix the problem.

### Repro

```
# WORKSPACE
http_file(
name = "available_port_finder",
downloaded_file_path = "AvailablePortFinder.java",
urls = [
"https://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java?revision=1232764&view=co",
],
)
```

```
# BUILD
java_library(
name = "available_port_finder",
srcs = [
"@available_port_finder//:AvailablePortFinder.java",
],
)
```

Then run:
```
$ bazel build //:available_port_finder
```

From here, one gets this message:

```
ERROR: /usr/local/home/aryehh/Development/code/BUILD.bazel:11:13: no such package '@available_port_finder//': BUILD file not found in directory '' of external repository @available_port_finder. Add a BUILD file to a directory to mark it as a package. and referenced by '//:available_port_finder'
ERROR: Analysis of target '//:available_port_finder' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.172s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
```

The way to fix the issue is to put `"@available_port_finder//file"` in the `srcs` attribute of the `java_library`.

### Expected Behavior

Bazel tells the user to reference `file` instead of the `downloaded_file_path` (name of the file)

---

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

Debian Rodete

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

`bazel 5.3.1`

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

`release 5.3.1`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the `http_file` and `java_library` example with `bazel build //:available_port_finder`, then trace how the external repository reference is diagnosed. Done means the error explains that `srcs` should reference `file` rather than the `downloaded_file_path` name, with the reported reproduction covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.