Skip to content

Commit

Permalink
Merge pull request #346 from gmkumar2005/main
Browse files Browse the repository at this point in the history
Raise helpful error if `IOWebApp` fails to mount
  • Loading branch information
armanbilge authored Jan 29, 2024
2 parents 1812408 + 7a9126f commit 7703b48
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions calico/src/main/scala/calico/IOWebApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,13 @@ trait IOWebApp:
def render: Resource[IO, fs2.dom.HtmlElement[IO]]

def main(args: Array[String]): Unit =
val rootElement = window.document.getElementById(rootElementId).map(_.get)
rootElement.flatMap(render.renderInto(_).useForever).unsafeRunAndForget()
window
.document
.getElementById(rootElementId)
.flatMap {
case Some(root) => render.renderInto(root).useForever
case None =>
IO.raiseError(new NoSuchElementException(
s"Unable to mount ${getClass.getSimpleName.init} into element with id \"$rootElementId\", does it exist in the HTML?"))
}
.unsafeRunAndForget()

0 comments on commit 7703b48

Please sign in to comment.