You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import caseapp._
case class EwApiDemoOptions (
@ExtraName("l") displaySpeciesList: Boolean = false,
@ExtraName("s") displaySpecies: String = ""
) extends App {
if (displaySpeciesList) {
println("speciesList")
} else if (displaySpecies.nonEmpty) {
println("displaySpecies")
} else if (!displaySpeciesList && displaySpecies.isEmpty)
Console.err.println(CaseApp.helpMessage[EwApiDemoOptions])
}
object EwApiDemo extends AppOf[EwApiDemoOptions]
Calling with the -Xlint option enables the check for delayedinit-select, which causes this warning to appear several times: Selecting value displaySpeciesList from class EwApiDemoOptions, which extends scala.DelayedInit, is likely to yield an uninitialized value. Yes, I can specify:
But that turns off the warnings for any other delayed init issues that may exist. Is there another way to structure the program to avoid delayed initialization entirely?
Invoking a option that requires an argument, but failing to provide a value for the argument, should cause an error message to be generated and the program to stop. Instead, the feeble argument missing message is displayed and then an ugly exception is thrown:
$ sbt "runMain EwApiDemo2 -s"
... lots of output ...
argument missing
Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "run-main-0"
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:runMain for the full output.
[error] (compile:runMain) Nonzero exit code: 1
[error] Total time: 1 s, completed Mar 1, 2017 5:43:30 PM
Users should not see the exception. Instead, they should politely be told what happened, and what they need to do to correct the problem. A better output would be:
Error: the -s/--displaySpecies option requires an argument, but none was supplied. Please retry with a value for the option.
Until this is fixed, how might I catch the exception?
The text was updated successfully, but these errors were encountered:
Here is a short test program:
delayedinit-select
, which causes this warning to appear several times:Selecting value displaySpeciesList from class EwApiDemoOptions, which extends scala.DelayedInit, is likely to yield an uninitialized value
. Yes, I can specify:But that turns off the warnings for any other delayed init issues that may exist. Is there another way to structure the program to avoid delayed initialization entirely?
argument missing
message is displayed and then an ugly exception is thrown:Users should not see the exception. Instead, they should politely be told what happened, and what they need to do to correct the problem. A better output would be:
Until this is fixed, how might I catch the exception?
The text was updated successfully, but these errors were encountered: