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

JLine error when attempting to run the REPL with piped input #11978

Closed
deanwampler opened this issue Apr 3, 2021 · 6 comments · Fixed by #21330
Closed

JLine error when attempting to run the REPL with piped input #11978

deanwampler opened this issue Apr 3, 2021 · 6 comments · Fixed by #21330
Assignees
Labels
area:command line Issues tied to how our launchers handle on the command line. area:repl area:runner Issues tied to the scala runner command. itype:bug itype:crash

Comments

@deanwampler
Copy link
Contributor

deanwampler commented Apr 3, 2021

Scala 3.0.0-RC2. A command like the following:

$ scala <<EOF
:load somestuff.scala
EOF

or trying:

$ echo ":load src/script/scala/progscala3/hierarchy/Asserts.scala" | scala

Both cause this exception:

Exception in thread "main" java.lang.IllegalStateException: Unable to create a system terminal
	at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:323)
	at org.jline.terminal.TerminalBuilder.build(TerminalBuilder.java:265)
	at dotty.tools.repl.JLineTerminal.<init>(JLineTerminal.scala:23)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:123)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:114)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)

This is fairly well known issue, see for example https://youtrack.jetbrains.com/issue/IDEA-183619. I attempted to use the recommended fix, setting the property -Dorg.jline.terminal.dumb=true. I did this by passing the argument -J-Dorg.jline.terminal.dumb=true to the REPL, even though this argument is not documented for the REPL in the -help output. It appeared to be ignored or do nothing. I also tried setting the environment variable JAVA_OPTS=-Dorg.jline.terminal.dumb=true before starting the REPL, but that didn't work either. Finally, I even tried setting the property inside the REPL, i.e.,

$ scala <<EOF
System.setProperty("...", "...")
:load somestuff.scala
EOF

I would expect this to be too late. It also doesn't help.

Note that in the Scala 2.13 REPL, without setting the property, you get a warning that it will default to a dumb terminal, but otherwise appears to work fine.

@griggt
Copy link
Contributor

griggt commented Apr 3, 2021

These incantations using TERM=dumb seem to work (at least on Linux)

$ TERM=dumb scala <<EOF
:load somestuff.scala
EOF
$ echo ":load src/script/scala/progscala3/hierarchy/Asserts.scala" | TERM=dumb scala

But we should probably gracefully fall back to a dumb terminal like Scala 2 does, as was also suggested here.

@griggt griggt self-assigned this Apr 3, 2021
@deanwampler
Copy link
Contributor Author

I just noticed in #11707 that using TERM=dumb should work. I confirmed it works on MacOS, too, just now. Thanks!

@catap
Copy link

catap commented Apr 13, 2024

Interesting that without TERM=dumb it simple doesn't work on OpenBSD

@catap
Copy link

catap commented Apr 24, 2024

#19744 may fixe this

@Gedochao Gedochao added itype:bug itype:crash area:runner Issues tied to the scala runner command. labels Jul 4, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Jul 4, 2024

Sadly, this is still broken, even on the new scala runner / Scala CLI.

echo 'object Example { def smth = "smth" }' |scala-cli repl _   
# Compiling project (Scala 3.4.2, JVM (17))
# Compiled project (Scala 3.4.2, JVM (17))
# Exception in thread "main" java.lang.IllegalStateException: Unable to create a terminal
# 	at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:394)
# 	at org.jline.terminal.TerminalBuilder.build(TerminalBuilder.java:362)
# 	at dotty.tools.repl.JLineTerminal.<init>(JLineTerminal.scala:25)
# 	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:145)
# 	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:136)
# 	at dotty.tools.repl.Main$.main(Main.scala:7)
# 	at dotty.tools.repl.Main.main(Main.scala)
# 	Suppressed: java.io.IOException: Unable to find terminal provider ffm
# 		at org.jline.terminal.spi.TerminalProvider.load(TerminalProvider.java:74)
# 		at org.jline.terminal.TerminalBuilder.checkProvider(TerminalBuilder.java:667)
# 		at org.jline.terminal.TerminalBuilder.getProviders(TerminalBuilder.java:632)
# 		at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:395)
# 		... 6 more
# 	Suppressed: java.io.IOException: Unable to find terminal provider jni
# 		at org.jline.terminal.spi.TerminalProvider.load(TerminalProvider.java:74)
# 		at org.jline.terminal.TerminalBuilder.checkProvider(TerminalBuilder.java:667)
# 		at org.jline.terminal.TerminalBuilder.getProviders(TerminalBuilder.java:634)
# 		at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:395)
# 		... 6 more
# 	Suppressed: java.io.IOException: Unable to find terminal provider jansi
# 		at org.jline.terminal.spi.TerminalProvider.load(TerminalProvider.java:74)
# 		at org.jline.terminal.TerminalBuilder.checkProvider(TerminalBuilder.java:667)
# 		at org.jline.terminal.TerminalBuilder.getProviders(TerminalBuilder.java:636)
# 		at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:395)
# 		... 6 more
# 	Suppressed: java.io.IOException: Unable to load terminal provider jna: null
# 		at org.jline.terminal.spi.TerminalProvider.load(TerminalProvider.java:71)
# 		at org.jline.terminal.TerminalBuilder.checkProvider(TerminalBuilder.java:667)
# 		at org.jline.terminal.TerminalBuilder.getProviders(TerminalBuilder.java:638)
# 		at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:395)
# 		... 6 more
# 	Caused by: java.lang.reflect.InvocationTargetException
# 		at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
# 		at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
# 		at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
# 		at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
# 		at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
# 		at org.jline.terminal.spi.TerminalProvider.load(TerminalProvider.java:69)
# 		... 9 more
# 	Caused by: java.lang.UnsupportedOperationException: Unsupported platform mac-aarch64
# 		at org.jline.terminal.impl.jna.JnaNativePty.isatty(JnaNativePty.java:194)
# 		at org.jline.terminal.impl.jna.JnaNativePty.isPosixSystemStream(JnaNativePty.java:170)
# 		at org.jline.terminal.impl.jna.JnaTerminalProvider.checkSystemStream(JnaTerminalProvider.java:124)
# 		at org.jline.terminal.impl.jna.JnaTerminalProvider.<init>(JnaTerminalProvider.java:31)
# 		... 15 more

@Gedochao Gedochao assigned mbovel and unassigned griggt Jul 4, 2024
@Gedochao Gedochao added the area:command line Issues tied to how our launchers handle on the command line. label Jul 5, 2024
@mbovel
Copy link
Member

mbovel commented Aug 5, 2024

Reading #11707 it seems to me that the right thing to do here might just be to keep the default value of dump to null instead of setting it to false when the dump terminal is not forced. This would allow JLine to fall back to a dump terminal if needed.

smarter added a commit that referenced this issue Aug 6, 2024
Set the `dumb` JLine option to `null` instead of `false` when a dumb
terminal is not forced. This allows JLine to fall back to a dumb
terminal if needed.

Fixes #11978.

Before:

```
➜ ~/dotty git:(mb/11978) ✗ echo 'object Example { def smth = "smth" }' | bin/scala
The `--offline` option is experimental
Please bear in mind that non-ideal user experience should be expected.
If you encounter any bugs or have feedback to share, make sure to reach out to the maintenance team at https://github.com/VirtusLab/scala-cli
Exception in thread "main" java.lang.IllegalStateException: Unable to create a terminal
        at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:394)
        at org.jline.terminal.TerminalBuilder.build(TerminalBuilder.java:362)
        at dotty.tools.repl.JLineTerminal.<init>(JLineTerminal.scala:34)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:145)
        at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:136)
        at dotty.tools.repl.Main$.main(Main.scala:7)
        at dotty.tools.repl.Main.main(Main.scala)
        Suppressed: java.io.IOException: Unable to find terminal provider ffm
                at org.jline.terminal.spi.TerminalProvider.load(TerminalProvider.java:74)
                at org.jline.terminal.TerminalBuilder.checkProvider(TerminalBuilder.java:667)
                at org.jline.terminal.TerminalBuilder.getProviders(TerminalBuilder.java:632)
                at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:395)
                ... 6 more
        Suppressed: java.io.IOException: Unable to find terminal provider jni
                at org.jline.terminal.spi.TerminalProvider.load(TerminalProvider.java:74)
                at org.jline.terminal.TerminalBuilder.checkProvider(TerminalBuilder.java:667)
                at org.jline.terminal.TerminalBuilder.getProviders(TerminalBuilder.java:634)
                at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:395)
                ... 6 more
        Suppressed: java.io.IOException: Unable to find terminal provider jansi
                at org.jline.terminal.spi.TerminalProvider.load(TerminalProvider.java:74)
                at org.jline.terminal.TerminalBuilder.checkProvider(TerminalBuilder.java:667)
                at org.jline.terminal.TerminalBuilder.getProviders(TerminalBuilder.java:636)
                at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:395)
                ... 6 more
```

After:

```
➜  ~/dotty git:(mb/11978) echo 'object Example { def smth = "smth" }' | bin/scala
The `--offline` option is experimental
Please bear in mind that non-ideal user experience should be expected.
If you encounter any bugs or have feedback to share, make sure to reach out to the maintenance team at https://github.com/VirtusLab/scala-cli
Aug 05, 2024 3:53:49 PM org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
Welcome to Scala 3.6.0-RC1-bin-SNAPSHOT-git-dce4377 (17.0.8, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> // defined object Example

scala> %                                                                                                                         
➜  ~/dotty 
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:command line Issues tied to how our launchers handle on the command line. area:repl area:runner Issues tied to the scala runner command. itype:bug itype:crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants