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

Trying to get desired behavior #51

Open
mslinn opened this issue Mar 2, 2017 · 0 comments
Open

Trying to get desired behavior #51

mslinn opened this issue Mar 2, 2017 · 0 comments

Comments

@mslinn
Copy link

mslinn commented Mar 2, 2017

Here is a short test program:

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]
  1. 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:
scalacOptions ++= Seq(
  "-Xlint",
  "-Xlint:-delayedinit-select"
)

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?

  1. 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?

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

No branches or pull requests

1 participant