bazel-contrib / bazel-contrib/rules_go

Discussion - Friendly compilation errors

Open
#2,799 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
762
Avg merge
1d 11h
Merged PRs (30d)
12

Description

In addition to Go, I build Java and JavaScript (via rules_closure) with Bazel, and the error messages from rules_go still compare unfavorably, even with the recent improvements (#2061, #2664).

Here's what a simple error looks like for us today:
```
$ bazel build //gocode/src/corp/analytics/searchterms:go_default_library
INFO: Analyzed target //gocode/src/corp/analytics/searchterms:go_default_library (358 packages loaded, 9325 targets configured).
INFO: Found 1 target...
ERROR: /Users/robfig/alpha/gocode/src/corp/analytics/searchterms/BUILD.bazel:4:11: GoCompilePkg gocode/src/corp/analytics/searchterms/go_default_library.a failed (Exit 1) builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src gocode/src/corp/analytics/searchterms/dataloader.go -src ... (remaining 73 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
gocode/src/corp/analytics/searchterms/redshiftcopier.go:14:2: imported and not used: "corp/net/rpc"
compilepkg: error running subcommand external/go_sdk/pkg/tool/darwin_amd64/compile: exit status 2
Target //gocode/src/corp/analytics/searchterms:go_default_library failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 59.019s, Critical Path: 24.86s
INFO: 589 processes: 589 darwin-sandbox.
FAILED: Build did NOT complete successfully
Bazel exited with status code 1
```

A typical Java error:
```
INFO: Analyzed target //src/com/corp/users/remotelogin:RemoteLoginMailFwdServer (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Users/robfig/alpha/src/com/corp/crm/mailing/BUILD.bazel:34:13: Building src/com/corp/crm/mailing/libmailing.jar (19 source files) failed (Exit 1)
src/com/corp/crm/mailing/SendRemoteLoginEmailOperation.java:89: error: cannot find symbol
b.setAttachmentContent(ByteString.copyFrom(attachmentBytes));
^
symbol: variable ByteString
location: class SendRemoteLoginEmailOperation
Target //src/com/corp/users/remotelogin:RemoteLoginMailFwdServer failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 8.796s, Critical Path: 6.00s
INFO: 3 processes: 3 darwin-sandbox.
FAILED: Build did NOT complete successfully
Bazel exited with status code 1
```

A typical JavaScript error:
```
ERROR: /Users/robfig/alpha2/src/com/corp/knowledgesearch/knowledgesearchstorm/public/js/BUILD.bazel:4:18: Couldn't build file src/com/corp/knowledgesearch/knowledgesearchstorm/public/js/knowledgesearchstorm.js: Compiling 621 JavaScript files to src/com/corp/knowledgesearch/knowledgesearchstorm/public/js/knowledgesearchstorm.js failed (Exit 1)
bazel-out/darwin-fastbuild/bin/src/com/corp/analytics/js/insight.js:114: ERROR - initializing variable
found : *
required: string
let heroNumber = tableConfig && tableConfig.totalNumbers[tableConfig.sortColIndex];
^
ProTip: "JSC_TYPE_MISMATCH" or "checkTypes" can be added to the `suppress` attribute of:
//src/com/corp/analytics/js:analytics
Alternatively /** @suppress {checkTypes} */ can be added to the source file.

1 error(s), 0 warning(s), 87.1% typed
```

There are three notable differences:
1. The line of code is printed with a caret pointing out the identified source location. A side effect is that it creates vertical space which calls attention to the errors, instead of combing through dense lines of text.
2. The underlying build command is suppressed by default, reducing the amount of noise. I recall that it appeared impossible without a change to Bazel, but JavaScript is not a privileged language and appears to accomplish it, so it must be possible.
3. rules_closure bolds the line with the error message (with ERROR in red), which makes it stand out even more. (Screenshot attached)
image

Any thoughts? Does this seem like a worthy line of work to pursue?

Contributor guide

Open the contributing guide

Research direction

Use the Go, Java, and JavaScript error examples in the issue as comparison cases. The issue names no rules_go file, test, or entry point, so first locate the existing compilation-error handling and agree on scope. Done would mean an agreed approach for source-line carets, reduced command noise, and clearer error emphasis.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java, javascript
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.