Skip to content
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

Handle incorrect Scalac options and prevent printing ScalacWorker stacktraces #1606

Merged
merged 8 commits into from
Sep 9, 2024

Conversation

WojciechMazur
Copy link
Contributor

Description

  • Handle cases when passing invalid scalac options
  • Prevent printing internal stack traces of ScalaWorker on compilation failing in an expected way

Motivation

Fixes #1605
When passing invalid scalac options, eg. -source:not-existing the Scala compiler would either:

  • return None form Driver.setup leading to runtime exception in None.get (Scala 3)
  • would not create an instance in Driver.newCompiler required to create ProtoReporter or DepsTrackingReporter leading to reporter being not initialized (Scala 2)
    This fix handles both of this cases by termination executing earlier with a known exception.

In each of cases Scalac compiler would always show error message about which setting was invalid. This is expected behaviour. Because of that, there is no reason to print stack traces on invalid scalac setting from ScalaInvoker exposing internal implementaiton to the user. It can be handled by either not filling stack traces or introducing a common subtype handled in the worker.
The later option was chosen and additionally extended to handle expected compiler errors. This should reduce amount of boilerplate logs.

Copy link

google-cla bot commented Aug 30, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@simuons simuons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @WojciechMazur, overall looks good to me. Could you please go over my comments/questions and also please format code (in some places it's off).

2>&1 | grep -v "$expected"
}

test_logs_contains_no_stacktrace() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

@@ -88,7 +98,8 @@ public void checkPermission(Permission permission) {
code = e.code;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
if (e instanceof Interface.WorkerException) {}
Copy link
Collaborator

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.

Copy link
Contributor Author

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 the e.getMessage so previously there have been exception message printed twice. Let's only print either only exception message or stack trace

Copy link
Collaborator

@liucijus liucijus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @WojciechMazur!

@liucijus liucijus merged commit 5a2453e into bazelbuild:master Sep 9, 2024
2 checks passed
@WojciechMazur WojciechMazur deleted the handle-invalid-settings branch September 9, 2024 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scala compilation error with cross compilation produces additional Null Pointer Exception
3 participants