Skip to content

Add warnings support to render output #144

@osteele

Description

@osteele

Summary

Add a mechanism for the liquid engine to report warnings (non-fatal issues) alongside rendered output. This enables callers to detect and report problematic template patterns without failing the build.

Motivation

The immediate use case is dot-notation in assign tags ({% assign page.canonical_url = page.url %}). Ruby Jekyll/Liquid accepts this syntax without error, but it's effectively a no-op — the value is stored under the literal key "page.canonical_url" in assigns, but {{ page.canonical_url }} resolves by looking up page then .canonical_url on the page drop, so the assigned value is never accessible.

Currently, the liquid engine either:

  • Errors on this syntax (when JekyllExtensions is disabled) — breaking compatibility with Jekyll sites that use it
  • Silently accepts it (when JekyllExtensions is enabled) — hiding broken code

Neither is ideal. A warnings mechanism would let callers accept the syntax for compatibility while informing users their code doesn't do what they expect.

Proposed approach

Add a ParseAndRenderDetailed method (or similar) that returns a result struct including warnings:

type RenderResult struct {
    Output   []byte
    Warnings []Warning
}

type Warning struct {
    Loc     SourceLoc
    Message string
}

The existing ParseAndRender signature stays unchanged (discards warnings) for backward compatibility.

For the dot-notation assign case specifically:

  • When JekyllExtensions is disabled: treat as a warning (not an error), execute as a no-op
  • The warning message should explain that the syntax has no effect, e.g.: "{% assign page.custom_var = ... %} has no effect. Dot notation in assign creates an inaccessible variable."

Why return values rather than a callback

  • Fits naturally with callers that collect results before reporting (e.g., gojekyll collects errors across all pages before reporting)
  • Enables strict mode: render first, then check if len(warnings) > 0 && strict { return error }
  • Cleaner API — pure data in, data out, no threading concerns
  • No breaking changes to existing API

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions