Skip to content

Commit de5d16f

Browse files
committed
Better error messages for bad SVG lookups
Previously if a svg directive didn't find an icon the build would fail with a `java.util.NoSuchElementException` but without any indication of what file the bad lookup happen in. By using an Either and Laika's Directive's `evalMap` we get nicer build errors with file names and locations.
1 parent 8b99777 commit de5d16f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

build.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ object LaikaCustomizations {
272272
},
273273
TemplateDirectives.create("svg") {
274274
import TemplateDirectives.dsl.*
275-
attribute(0).as[String].map { icon =>
276-
TemplateElement(
277-
RawContent(NonEmptySet.of("html", "rss"), Icons(icon))
278-
)
275+
attribute(0).as[String].evalMap { icon =>
276+
Icons.get(icon).toRight(s"Unknown SVG icon '$icon'").map { svg =>
277+
TemplateElement(RawContent(NonEmptySet.of("html", "rss"), svg))
278+
}
279279
}
280280
}
281281
)

0 commit comments

Comments
 (0)