Skip to content

STTEDIT-4 Show backend error details in the template preview - #121

Merged
zburke merged 1 commit into
folio-org:mainfrom
slub:STTEDIT-4-show-backend-error-details
Sep 1, 2026
Merged

zburke merged 1 commit into
folio-org:mainfrom
slub:STTEDIT-4-show-backend-error-details

Conversation

@thomas-sc

@thomas-sc thomas-sc commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

A failed backend-rendered preview only showed the generic "The preview could not be rendered." useTemplatePreview dropped the error object, so the diagnostic that mod-template-engine returns was lost. A syntax error in a large template is currently a needle in a haystack.

  • The detail is extracted in the react-query queryFn (reading the response body is async while error is exposed synchronously) and attached to the thrown error.
  • BackendPreview renders the diagnostic below the existing generic message, plus a short excerpt of the source line with a caret where the response carries one; the full template dump is not rendered.
  • The body is read robustly (plain text, or JSON errors[].message); with no extractable detail the generic message is shown on its own.

How much detail arrives depends on the resolver: mustache.java returns one line without a position, the Handlebars resolver from MODTEMPENG-136 adds a source line and a caret. The parser does not assume the richer shape, so MODTEMPENG-136 is not a prerequisite. Both real responses are used as test fixtures.

Backwards compatible: no new or changed props, no dependency changes. Only the existing error state gains detail, and it is reachable solely for consumers that already opted into previewRenderer="backend". ui-circulation and staff slips keep the regex preview. No new interactive UI, so accessibility is unchanged.

mustache.java — diagnostic line only, no excerpt:
Screenshot-Render-Error-2

Handlebars (MODTEMPENG-136) — diagnostic, excerpt and caret:
Screenshot-Render-Error-3

Refs STTEDIT-4

The preview discarded the error object from the preview request, so a
failed render only produced a generic message. mod-template-engine
returns a diagnostic and, depending on the resolver, a source line with
a caret; that detail is now extracted in the query function and shown
below the generic message.

Extraction happens in the queryFn because reading the response body is
async while react-query exposes `error` synchronously.
@thomas-sc
thomas-sc marked this pull request as ready for review August 19, 2026 09:00
@thomas-sc
thomas-sc requested a review from a team as a code owner August 19, 2026 09:00

@zburke zburke left a comment

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.

Your detailed explanation of both the implementation and why we need it was super helpful; thank you!

@thomas-sc

Copy link
Copy Markdown
Contributor Author

Thanks @zburke , glad it was helpful. Is anything else needed to merge?

@zburke
zburke merged commit bb132e4 into folio-org:main Sep 1, 2026
13 checks passed
@thomas-sc
thomas-sc deleted the STTEDIT-4-show-backend-error-details branch September 2, 2026 06:51
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.

2 participants