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".
[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.
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.