From 8913518145cb1dc6efb3b6b40d115cb0a256c813 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 27 Jun 2022 11:40:53 +0200 Subject: [PATCH] JavaScriptKSYParser: propagate one CompilationProblem as exception 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. --- .../io/kaitai/struct/format/JavaScriptKSYParser.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/src/main/scala/io/kaitai/struct/format/JavaScriptKSYParser.scala b/js/src/main/scala/io/kaitai/struct/format/JavaScriptKSYParser.scala index 658354fc6..9a1317b06 100644 --- a/js/src/main/scala/io/kaitai/struct/format/JavaScriptKSYParser.scala +++ b/js/src/main/scala/io/kaitai/struct/format/JavaScriptKSYParser.scala @@ -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 { /** @@ -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 = {