scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

NumberFormatException because of tput No such device or address

Open francisdb opened this issue 3 years ago • 5 comments

Compiler version

3.1.3

Minimized code

echo "@main def main = println(util.Properties.versionMsg)" > test.scala
scala -nocompdaemon test.scala

This code is part of a docker build on a amazon corretto 17.0.4 base image see https://github.com/sbt/docker-sbt/pull/207

Output

tput: terminal attributes: No such device or address

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Integer.parseInt(Integer.java:678)
	at java.base/java.lang.Integer.parseInt(Integer.java:786)
	at scala.collection.StringOps$.toInt$extension(StringOps.scala:915)
	at dotty.tools.dotc.config.ScalaSettings$.defaultPageWidth(ScalaSettings.scala:39)
	at dotty.tools.dotc.config.CommonScalaSettings.$init$(ScalaSettings.scala:105)
	at dotty.tools.dotc.config.ScalaSettings.<init>(ScalaSettings.scala:14)
	at dotty.tools.dotc.core.Contexts$ContextBase.<init>(Contexts.scala:850)
	at dotty.tools.dotc.Driver.initCtx(Driver.scala:59)
	at dotty.tools.scripting.ScriptingDriver.compileAndRun(ScriptingDriver.scala:17)
	at dotty.tools.scripting.Main$.main(Main.scala:45)
	at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:249)
	at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:268)
	at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)

Expectation

This runs fine and prints the scala version

References

introduced in https://github.com/lampepfl/dotty/pull/10304

https://github.com/lampepfl/dotty/blob/1130c52a6476d473b41a598e23f0415e0f8d76dc/dist/bin/common#L31-L34

Fix

probably this should default to 80 in case tput fails or not set COLUMNS?

see https://docs.scala-lang.org/scala3/guides/migration/options-new.html

Workaround

looks like -pagewidth 80 4f803eba2c9a942b5af8643393243537a2c1b195 was applied to tests to fix a similar issue

More testing

docker run --rm amazoncorretto:17.0.4 tput -Tdumb cols
tput: terminal attributes: No such device or address

docker run --rm eclipse-temurin:17.0.3_7-jdk tput -Tdumb cols
80

francisdb avatar Aug 01 '22 15:08 francisdb

I've not managed to reproduce it locally using Ubuntu 20.04 LTS, JDK 11/17 Amazon Correctto, and any of the bash, zsh, sh shells. The only way of reproducing it so far involves building docker image locally based on the referenced PR.

@francisdb btw. It looks like your script has a small bug, util.Properties.versionMsg contains a version of Scala 2 library (since Scala 3 uses Scala 2.13 stdlib to allow for cross building between the two)

WojciechMazur avatar Aug 02 '22 13:08 WojciechMazur

@francisdb btw. It looks like your script has a small bug, util.Properties.versionMsg contains a version of Scala 2 library (since Scala 3 uses Scala 2.13 stdlib to allow for cross building between the two)

Thanks, got a better in-code one-liner that prints the correct scala version in scala 3?

francisdb avatar Aug 02 '22 14:08 francisdb

hmm, I edited the description but this must have been lost. Edited it again (docker run stuff)

francisdb avatar Aug 02 '22 14:08 francisdb

Thanks, got a better in-code one-liner that prints the correct scala version in scala 3?

Not really a one-liner, but works: https://gist.github.com/romanowski/de14691cab7340134e197419bc48919a You can always just curl the gist source and run it

WojciechMazur avatar Aug 02 '22 15:08 WojciechMazur

(cool, I didn't know about that gist; this PR links to it from the FAQ entry on the subject: https://github.com/scala/docs.scala-lang/pull/2485)

SethTisue avatar Aug 03 '22 00:08 SethTisue