Skip to content

Commit

Permalink
JavaScript: store validation errors in _debug before throwing
Browse files Browse the repository at this point in the history
This provides the necessary KSC support to reliably indicate validation
errors and assign them to specific fields in the Web IDE object tree
(this will be implemented as part of
kaitai-io/kaitai_struct_webide#156 for easier
debugging).
  • Loading branch information
generalmimon committed Feb 20, 2024
1 parent 755bcbe commit b6756f7
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,15 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
val errArgsStr = errArgs.map(translator.translate).mkString(", ")
out.puts(s"if (!(${translator.translate(checkExpr)})) {")
out.inc
out.puts(s"throw new ${ksErrorName(err)}($errArgsStr);")
val errObj = s"new ${ksErrorName(err)}($errArgsStr)"
if (attrDebugNeeded(attrId)) {
val debugName = attrDebugName(attrId, NoRepeat, true)
out.puts(s"var _err = $errObj;")
out.puts(s"$debugName.validationError = _err;")
out.puts("throw _err;")
} else {
out.puts(s"throw $errObj;")
}
out.dec
out.puts("}")
}
Expand Down

0 comments on commit b6756f7

Please sign in to comment.