Scala sbt "(run-main-0) ... Nonzero exit code" in CI
sbt ran your main method and the program threw or exited non-zero. The (run-main-0) prefix marks the forked run thread; the real cause is the exception printed just above the sbt summary.
What this error means
sbt run fails with "[error] (run-main-0) <Exception>" followed by a stack trace, then "[error] Nonzero exit code returned from runner: 1".
sbt
[error] (run-main-0) java.lang.RuntimeException: DATABASE_URL is not set
[error] java.lang.RuntimeException: DATABASE_URL is not set
[error] at com.example.Main$.main(Main.scala:11)
[error] Nonzero exit code returned from runner: 1Common causes
The program threw at runtime
Compilation succeeded but main hit a runtime error - a missing env var, a failed connection, an unhandled exception.
The application called exit with a non-zero code
Code reached sys.exit(1) or a framework returned a failure status, which sbt surfaces as a nonzero runner exit.
How to fix it
Read the exception above the summary
- Scroll up to the
(run-main-0)line and its stack trace. - Fix the runtime cause it names (set the env var, handle the failure).
- Re-run
sbt runto confirm it exits zero.
Provide required runtime configuration
Supply the environment the program expects so main does not throw on startup.
.github/workflows/ci.yml
env:
DATABASE_URL: postgres://localhost:5432/app_testHow to prevent it
- Validate required configuration at startup with clear messages.
- Set runtime env vars the application needs in the CI step.
- Distinguish compile failures from runtime failures by reading the prefix.
Related guides
Scala sbt server lock "server is already bootstrapping" in CIFix Scala sbt server lock errors in CI - a second sbt cannot take the project lock because a server is alread…
Scala sbt "OutOfMemoryError: Metaspace" in CIFix Scala sbt "java.lang.OutOfMemoryError: Metaspace" in CI - the sbt JVM exhausted class metadata space whil…
Scala sbt "object X is not a member of package Y" in CIFix Scala "[error] object X is not a member of package Y" in CI - an import points at a package path that the…