Skip to content

Better error messages on directive fails#623

Merged
valencik merged 5 commits intomainfrom
directive-errors
Mar 29, 2026
Merged

Better error messages on directive fails#623
valencik merged 5 commits intomainfrom
directive-errors

Conversation

@valencik
Copy link
Copy Markdown
Member

@valencik valencik commented Mar 29, 2026

Closes #622

Now when we have bad LaTeX source in a post we surface the KaTeX parse error:

/blog/algebraic-api-design.md

  [34]: One or more errors processing directive 'math': ParseError: KaTeX parse error: Undefined control sequence: \meow at position 6:  (G, \̲m̲e̲o̲w̲)

  - *Set* and *operator*: @:math() (G, \meow) @:@
                          ^
        at laika.api.errors.InvalidDocuments$.apply(errors.scala:89)
        at laika.api.errors.InvalidDocuments$.from$$anonfun$4(errors.scala:125)

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.
@valencik valencik self-assigned this Mar 29, 2026
def apply(
latex: String,
displayMode: Boolean = false
): Either[String, String] =
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this perhaps no longer be apply and instead be something like parse or render?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd say so -- once it's becoming effectful (which this kind of is), apply doesn't feel quite idiomatically right any more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, renamed to render

@valencik valencik marked this pull request as ready for review March 29, 2026 14:32
@valencik valencik requested a review from armanbilge March 29, 2026 14:32
@valencik
Copy link
Copy Markdown
Member Author

Let's merge #584 first, and then I'll fix conflicts here.

def apply(
latex: String,
displayMode: Boolean = false
): Either[String, String] =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd say so -- once it's becoming effectful (which this kind of is), apply doesn't feel quite idiomatically right any more.

@valencik valencik merged commit 2084139 into main Mar 29, 2026
1 check passed
@valencik valencik deleted the directive-errors branch March 29, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not great build errors when directives fail

2 participants