Skip to content
Latchkey

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: 1

Common 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

  1. Scroll up to the (run-main-0) line and its stack trace.
  2. Fix the runtime cause it names (set the env var, handle the failure).
  3. Re-run sbt run to 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_test

How 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →