-
-
Notifications
You must be signed in to change notification settings - Fork 286
Handle incorrect Scalac options and prevent printing ScalacWorker stacktraces #1606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
liucijus
merged 8 commits into
bazel-contrib:master
from
WojciechMazur:handle-invalid-settings
Sep 9, 2024
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8172568
Improve handling of invalid settings passed to Scala compiler. Throw …
WojciechMazur 3f0e5ba
Prevent printing stack trace of ScalacInvoker on known compilation er…
WojciechMazur 9f352e9
Run reporter.flush in Scala3
WojciechMazur 90766b4
Restore previous error messages
WojciechMazur d4f20b9
Addi tests to ensure corect error message and no stack traces are shown
WojciechMazur 74d0759
Remove unused code from test_invalid_scalacopts.sh
WojciechMazur 585ebf4
Print exception message only once. Previously printed in both e.getMe…
WojciechMazur 772a05c
Ident with spaces instead of tabs
WojciechMazur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# shellcheck source=./test_runner.sh | ||
|
||
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
. "${dir}"/test_runner.sh | ||
. "${dir}"/test_helper.sh | ||
runner=$(get_test_runner "${1:-local}") | ||
|
||
test_logs_contains() { | ||
scalaVersion=$1 | ||
expected=$2 | ||
|
||
bazel build \ | ||
--repo_env=SCALA_VERSION=${scalaVersion} \ | ||
//test_expect_failure/scalacopts_invalid:empty \ | ||
2>&1 | grep "$expected" | ||
} | ||
|
||
test_logs_not_contains() { | ||
scalaVersion=$1 | ||
expected=$2 | ||
|
||
bazel build \ | ||
--repo_env=SCALA_VERSION=${scalaVersion} \ | ||
//test_expect_failure/scalacopts_invalid:empty \ | ||
2>&1 | grep -v "$expected" | ||
} | ||
|
||
test_logs_contains_no_stacktrace() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used anywhere? |
||
bazel build \ | ||
--extra_toolchains="//test_expect_failure/scalacopts_invalid" \ | ||
--repo_env=SCALA_VERSION=${scalaVersion} \ | ||
//test_expect_failure/scalacopts_invalid:empty | ||
} | ||
|
||
for scalaVersion in 2.12.19 2.13.14 3.3.3; do | ||
if [[ "$scalaVersion" == 3.* ]]; then | ||
$runner test_logs_contains $scalaVersion "not-existing is not a valid choice for -source" | ||
else | ||
$runner test_logs_contains $scalaVersion "bad option: '-source:not-existing'" | ||
fi | ||
$runner test_logs_contains $scalaVersion 'Failed to invoke Scala compiler, ensure passed options are valid' | ||
$runner test_logs_not_contains $scalaVersion 'at io.bazel.rulesscala.scalac.ScalacWorker.main' | ||
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
load("//scala:scala.bzl", "scala_library") | ||
|
||
scala_library( | ||
name = "empty", | ||
srcs = ["Empty.scala"], | ||
scalacopts = ["-source:not-existing"], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package test_expect_failure.scalacopts_invalid | ||
|
||
class Empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here instead of empty block you could do
System.err.println(e.getMessage());
?I think message is printed with
e.printStackTrace();
in an else statement as well. If not then leave this as is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, the
e.printStackTrace
would print thee.getMessage
so previously there have been exception message printed twice. Let's only print either only exception message or stack trace