Skip to content

Commit

Permalink
JavaScriptKSYParser: propagate one CompilationProblem as exception
Browse files Browse the repository at this point in the history
This is more of a temporary solution, but it's needed - currently
compiled files are returned regardless of whether there are any
problems, and problems are not propagated outside the compiler.
  • Loading branch information
generalmimon committed Jun 27, 2022
1 parent 1cbaff9 commit 8913518
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.kaitai.struct.{JavaScriptImporter, Main, RuntimeConfig}
import scala.concurrent.Future
import scala.scalajs.js
import scala.concurrent.ExecutionContext.Implicits.global
import io.kaitai.struct.problems.ProblemSeverity

object JavaScriptKSYParser {
/**
Expand All @@ -17,7 +18,13 @@ object JavaScriptKSYParser {
val yamlScala = yamlJavascriptToScala(yaml)
val firstSpec = ClassSpec.fromYaml(yamlScala, None)
val specs = new JavaScriptClassSpecs(importer, firstSpec)
Main.importAndPrecompile(specs, config).map((_) => specs)
Main.importAndPrecompile(specs, config).map{ problems =>
// throw the first (if any) severe (not a warning) problem as an exception
problems.find(p => p.severity != ProblemSeverity.Warning) match {
case Some(problem) => throw problem.toException
case None => specs
}
}
}

def yamlJavascriptToScala(src: Any): Any = {
Expand Down

0 comments on commit 8913518

Please sign in to comment.