Skip to content

Commit

Permalink
Fix non-zero exit code on error (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-studios authored Jan 16, 2024
2 parents cbff76e + 0273311 commit 2ba7d1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ lazy val effekt: CrossProject = crossProject(JSPlatform, JVMPlatform).in(file("e

Compile / unmanagedResourceDirectories += (ThisBuild / baseDirectory).value / "licenses",

// cli flag so sbt doesn't crash when effekt does
addCommandAlias("run", "runMain effekt.Server --noexit-on-error"),

assembleBinary := {
val jarfile = assembly.value
Expand Down
6 changes: 5 additions & 1 deletion effekt/jvm/src/main/scala/effekt/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait Driver extends kiama.util.Compiler[EffektConfig, EffektError] { outer =>
* If no file names are given, run the REPL
*/
override def run(config: EffektConfig): Unit =
if (config.filenames().isEmpty && !config.server() && !config.compile()) {
if (config.repl()) {
new Repl(this).run(config)
// This is overridden by kiama.Server to launch the LSP server.
// TODO: remove dynamic dispatch here and consider replacing inheritance by composition.
Expand Down Expand Up @@ -100,5 +100,9 @@ trait Driver extends kiama.util.Compiler[EffektConfig, EffektError] { outer =>
def afterCompilation(source: Source, config: EffektConfig)(implicit C: Context): Unit = {
// report messages
report(source, C.messaging.buffer, config)

// exit with non-zero code if not in repl/server mode and messaging buffer contains errors
if (config.exitOnError() && C.messaging.hasErrors)
sys.exit(1)
}
}
9 changes: 9 additions & 0 deletions effekt/jvm/src/main/scala/effekt/EffektConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class EffektConfig(args: Seq[String]) extends REPLConfig(args) {
noshort = true
)

val exitOnError: ScallopOption[Boolean] = toggle(
"exit-on-error",
descrYes = "Exit with non-zero exit code on error",
default = Some(!repl() && !server()),
noshort = true
)

/**
* Tries to find the path to the standard library. Proceeds in the following
* order:
Expand Down Expand Up @@ -121,6 +128,8 @@ class EffektConfig(args: Seq[String]) extends REPLConfig(args) {

def interpret(): Boolean = !server() && !compile() && !build()

def repl(): Boolean = filenames().isEmpty && !server() && !compile()

validateFilesIsDirectory(includePath)

// force some other configs manually to initialize them when compiling with native-image
Expand Down

0 comments on commit 2ba7d1f

Please sign in to comment.