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

Fix scala runner exit codes #15604

Merged
merged 9 commits into from
Jul 11, 2022
Merged

Fix scala runner exit codes #15604

merged 9 commits into from
Jul 11, 2022

Conversation

rochala
Copy link
Contributor

@rochala rochala commented Jul 6, 2022

Adoption of scala2 exit code implementation. Fixes #15022

Now main runner returns proper status code when it fails during runtime.
Also tried to cleanup this class a bit.

I added tests for all combinations of MainGenericCompiler / Runner that I could think of and found that -print-tasty flag was returning wrong exit codes despite errors. I didn't know it that's the best place to put them but i think they count as scripting tests.

The last change that I've made is improving error messages for scala expressions (-e). Before it created virtual files from compileFromStrings even though we explicitly passed one source. It lead to very high horizontal length of stack trace making it less clear as those files had UUID in their name. It now creates single file to make it shorter.

Exception in thread "main" java.lang.RuntimeException
        at compileFromString$minus86740691$minus6469$minus484b$minusaf4f$minus40ffc988311b$package$.main(compileFromString-86740691-6469-484b-af4f-40ffc988311b.scala:2)
        at main.main(compileFromString-86740691-6469-484b-af4f-40ffc988311b.scala:1)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at dotty.tools.scripting.StringDriver.compileAndRun(StringDriver.scala:36)
        at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:258)
        at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:268)
        at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)

@rochala rochala requested a review from bishabosha July 8, 2022 10:38
@rochala rochala marked this pull request as ready for review July 8, 2022 10:38
@rochala
Copy link
Contributor Author

rochala commented Jul 8, 2022

I'll delete this additional file after fixes in code review to not rerun tests again. touchedFile.out

@@ -146,6 +146,8 @@ class ScriptingTests:
if touchedFile.exists then
printf("success: executable jar created file %s\n", touchedFile)
assert( touchedFile.exists, s"expected to find file ${touchedFile}" )
touchedFile.delete
assert( !touchedFile.exists, s"unable to delete ${touchedFile}" )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found that touchedFile.out was a leftover from this test. Now it should be deleted properly.

@rochala rochala requested review from griggt and bishabosha July 8, 2022 17:11
@griggt griggt dismissed their stale review July 8, 2022 17:27

changes were made as requested

Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

minor point but it would be nice if for ExecuteMode.Expression the StringDriver.compileAndRun was escaped for the StringDriverException to just print the message, like what happens for ScriptingException.

Currently we get a stack trace for compilation errors in the -e mode:

~/workspace/scripts » ../dotty/dist/target/pack/bin/scala -e 'prinln(2)' || echo "fail"
-- [E006] Not Found Error: expression:2:2 --------------------------------------
2 |  prinln(2)
  |  ^^^^^^
  |  Not found: prinln
  |
  | longer explanation available when compiling with `-explain`
dotty.tools.scripting.StringDriverException: Errors encountered during compilation
	at dotty.tools.scripting.StringDriverException$.apply(StringDriver.scala:52)
	at dotty.tools.scripting.StringDriver.compileAndRun(StringDriver.scala:31)
	at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:261)
	at dotty.tools.MainGenericRunner$.process(MainGenericRunner.scala:271)
	at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:281)
	at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)
fail

Ideally it would just be

~/workspace/scripts » ../dotty/dist/target/pack/bin/scala -e 'prinln(2)' || echo "fail"
-- [E006] Not Found Error: expression:2:2 --------------------------------------
2 |  prinln(2)
  |  ^^^^^^
  |  Not found: prinln
  |
  | longer explanation available when compiling with `-explain`
Errors encountered during compilation
fail

@rochala
Copy link
Contributor Author

rochala commented Jul 11, 2022

Yeah, my mistake, and while we're at expression flag. In scala 2 -e flag is called as execute while here it's called expression. Shouldn't scala3 match scala2 naming ?

@bishabosha
Copy link
Member

bishabosha commented Jul 11, 2022

while we're at expression flag. In scala 2 -e flag is called as execute while here it's called expression. Shouldn't scala3 match scala2 naming ?

I would say no: - I don't think its a big deal because its internal details, but could also cause confusion with other modes, such as ExecuteMode.Run

scoverage.coverage Outdated Show resolved Hide resolved
@bishabosha bishabosha self-requested a review July 11, 2022 11:24
@bishabosha bishabosha enabled auto-merge July 11, 2022 11:24
@bishabosha bishabosha merged commit 6efd92d into scala:main Jul 11, 2022
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
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 must not exit with 0 if the program threw an uncaught exception
4 participants