Compile errors
lttr.Compile checks everything about a template that doesn't depend on data or on the renderer: the Comark source, the frontmatter, every component against its kit schema, and every merge tag and binding against your Go type. It reports every problem it finds at once, each with the template name, line and column. What depends on data (a missing value, a URL, the profile) is checked by Render, with the same kind of position.
Read an error
Each error is one line: name:line:col: message. Lines and columns start at 1, and columns count bytes. When there are several, Compile joins them with errors.Join, so printing the error prints one per line.
A few things decide what you see:
- A parse error stops early. If the Comark itself can't be parsed (an unclosed frontmatter, an invalid attribute list, bad props YAML, invalid UTF-8), you get that one error, the earliest in the file.
- The rest come together. Frontmatter errors first, then slots, then the body in source order. A component's own checks (its counts,
max_kind,sequence, its children,required_with) are reported after the errors inside it, so they can appear below a later line. A rule that compares siblings, such asmust_follow, is reported after the components it compares. - Component errors point at the component. A missing or unknown attribute, a wrong count or a missing binding is reported at the first
:of the opener. A block the component doesn't take points at the block, and a tag error at the tag. - Exact duplicates are dropped.
- An unknown name comes with a suggestion when a known one is close:
(did you mean code?)at the end of the message. It applies to merge-tag and binding paths, components and their aliases, attributes, span classes, tokens named inkit.yamlandcomponent.yaml, and in kit templates totokenandvarnames and schema keys. How close counts depends on the length: a name of one or two letters is matched only when the case alone differs, three to five letters allow one edit, and longer names allow two edits or a third of the length, whichever is more. A name far from every candidate gets none. A dotted name, such as a token, is matched segment by segment, each segment within the limit for its own length, socolr.textsuggestscolor.textandfont.monodoesn't suggestfont.sans. Between two equally close names, the one that only adds letters wins, since a left-out letter is the commonest typo:columssuggestscolumns, notcolumn.
Handle errors in Go
Every positioned error is an *ir.Error:
type Error struct {
Name string // template (or copy) name
Pos Pos
Msg string // ends with " (did you mean X?)" when Suggestion is set
// Suggestion is the known name nearest to the unknown one Msg quotes,
// for quick fixes: the text that replaces that name (".muted",
// ":order"; for a merge tag or binding, the whole path, such as
// "driver.rating" for {{drivr.rating}}); empty when none. Pos is where
// the error is reported, which is not necessarily where the name is
// written.
Suggestion string
}
errors.As finds the first one. To walk all of them, unwrap the joined error:
package main
import (
"errors"
"fmt"
"github.com/sulv-io/lttr"
"github.com/sulv-io/lttr/ir"
"github.com/sulv-io/lttr/kits/plain"
)
type Reset struct {
Code string `json:"code"`
ExpiresIn string `json:"expires_in"`
ResetURL string `json:"reset_url"`
}
const src = `---
template: auth.reset
profile: security
subject: Your reset code
---
# Reset your password
Your code is {{cod}}. It expires in {{expires_in}}.
::button{href="{{reset_url}}"}
::
`
func main() {
_, err := lttr.Compile[Reset](plain.MustKit(), "auth.reset", []byte(src))
if err == nil {
return
}
// The whole error: one "name:line:col: message" per line.
fmt.Println(err)
// Each joined error is an *ir.Error with its own position.
errs := []error{err}
if j, ok := err.(interface{ Unwrap() []error }); ok {
errs = j.Unwrap()
}
for _, e := range errs {
var ce *ir.Error
if errors.As(e, &ce) {
fmt.Printf("line %d, col %d: %s\n", ce.Pos.Line, ce.Pos.Col, ce.Msg)
}
}
}
auth.reset:9:14: unknown name "cod" (did you mean code?)
auth.reset:11:1: button: missing "label"
line 9, col 14: unknown name "cod" (did you mean code?)
line 11, col 1: button: missing "label"
Two errors have no position, because they are about the call rather than the template: lttr: nil kit, and lttr: template data must be a struct or a map with string keys, got string when T is neither.
MustCompile panics with the same joined error. Use it for package-level templates, so a broken template stops the service at startup, and Compile when the source comes from somewhere you don't control.
Read warnings
Warnings never fail a compile. They are on the compiled template, in Meta().Warnings, formatted name:line:col: warning: message, and are copied into every rendered Message.Warnings:
| Warning | Cause |
|---|---|
frontmatter: no preheader | The template has no preheader. The inbox then previews the first text of the email. |
malformed merge tag "{{ Name }}" | Something starts with {{ but isn't a valid tag, so it is sent as literal text. Usually an upper-case letter, a missing brace, or a bare | in a table cell. |
Render adds one of its own when the HTML is over 90 KB: html is … bytes; gmail clips at 102 KB. At 100 KB or more the same message is an error, because Gmail clips a message at 102 KB.
func TestTemplatesHaveNoWarnings(t *testing.T) {
for _, w := range orderShipped.Meta().Warnings {
t.Error(w) // e.g. order.shipped:1:1: warning: frontmatter: no preheader
}
}
Warnings are produced only when the template compiles. A template with errors reports the errors alone.
Lint from the command line
lttr lint compiles template files against a kit and prints errors as file:line:col: message and warnings as file:line:col: warning: message. It exits 1 when any file has an error.
With -kit plain (or a kit directory), a file whose template: names one of the kit's samples is compiled like that sample and rendered with its data from samples/samples.yaml, then its HTML is linted. Any other name is compiled as untyped data only. This copy of Plain's welcome.md breaks a rule on almost every line:
---
template: welcome
profile: default
subject: "Welcome to Example, {{first_name}}"
colour: blue
---
# Welcome, {{first_name}}
<p>Your workspace is ready.</p>
#### Next steps
> Most teams start here.
`{{workspace}}`{.small} is yours. See [the guide](https://example.com/g "Guide").
:note[Tip]{href="https://example.com/tips"}
::callout
Hello
::
::button{href="{{setup_url}}" label="Finish setting up" target="_blank"}
::
::image{src="{{cover_url}}"}
::
::columns
:::column
# Guides

:::
::
::footer
Questions? Reply to this email.
::
go run ./cmd/lttr lint -kit plain welcome.md
welcome.md:5:1: frontmatter: unknown key "colour"
welcome.md:10:1: raw html is not allowed
welcome.md:12:1: section: h4 is not allowed here
welcome.md:14:1: section: blockquote is not allowed here
welcome.md:16:1: attributes are only allowed on spans and inline components
welcome.md:16:39: section: link titles are not allowed
welcome.md:18:1: unknown inline component ":note"
welcome.md:20:1: unknown component "callout"
welcome.md:24:1: button: unknown attribute "target"
welcome.md:27:1: image: missing "alt"
welcome.md:32:1: column: h1 is not allowed here
welcome.md:33:1: column: images are not allowed here
welcome.md:30:1: columns: 2 to 3 column components, got 1
welcome.md:37:1: footer: content is not allowed
With the errors gone, lint renders the file, prints the warning and exits 0:
fixed.md:1:1: warning: frontmatter: no preheader
Plain's samples are untyped, so lint can't check their paths at compile time. -kit quiet compiles each file against the Go type of the Quiet example its template: names, so path errors show up too, alongside Quiet's schema rules. A copy of 01-box-on-its-way.md:
---
template: order.out_for_delivery
profile: buyer
subject: Your produce box is on its way
preheader: "Arriving at {{destination}} by {{eta}} today."
legal: yes
---
::statement{eyebrow="Order {{order_id}}" tone="red"}
# On its way.
## Due by {{eta}}
{{courier}} picked it up at {{picked_up_at}}. Call {{courier.nme}} on {{courier.phone}}.
:button[Track delivery]{href="{{track_url}}"}
::
::image{src="{{hero_url}}"}
::
::receipt{:order="order_id"}
::
::meta
### Courier
{{courier.name}} · ★ {{courier.rating.stars}}
::
:button[Track again]{href="{{track_url}}"}
go run ./cmd/lttr lint -kit quiet 01-box-on-its-way.md
01-box-on-its-way.md:6:1: frontmatter: "legal" must be a boolean
01-box-on-its-way.md:9:1: statement: tone must be "orange"
01-box-on-its-way.md:14:1: {{courier}} is quiet.Courier, not a scalar
01-box-on-its-way.md:14:52: unknown field "nme" in quiet.Courier (did you mean courier.name?)
01-box-on-its-way.md:14:71: unknown field "phone" in quiet.Courier
01-box-on-its-way.md:12:1: statement: at most one heading
01-box-on-its-way.md:19:14: unknown name "hero_url"
01-box-on-its-way.md:19:1: image: alt is required when src is set
01-box-on-its-way.md:22:1: receipt: :order is string, want quiet.Receipt
01-box-on-its-way.md:27:25: cannot descend into string at "courier.rating"
01-box-on-its-way.md:30:1: letter: :button is not allowed here
01-box-on-its-way.md:30:1: more than one :button in the template
-kit quiet, template: must name one of the nine examples (unknown template "auth.rest" (no data type registered) otherwise). For your own templates, compile them in a test: a package-level MustCompile fails go test on any error, and rendering each template with sample data checks the render-time rules too. See CLI and Goldens and testing.Fix common errors
Every message below was printed by lttr lint on a crafted template, against Plain unless the component is Quiet's. Quoted names and numbers change with your template.
Syntax
| Message | Cause and fix |
|---|---|
frontmatter: missing closing --- | The frontmatter has no closing --- line. |
duplicate attribute "width" | The same key twice in one {…}, or a key and its binding (steps and :steps). |
binding :src needs a value | A :key with no ="path". |
expected an attribute name | Something in {…} that isn't a key, a .class or a #id, often a stray quote. |
props: did not find expected ',' or ']' | A YAML error in a props block, reported on its line with a props: prefix. |
props: missing closing --- | A --- props block with no closing line. |
props: given twice | Both a --- props block and a yaml [props] fence. |
slots are reserved | A #name line inside a component. Remove it, or add a space for a heading: # Name. |
raw html is not allowed | An HTML tag or block. Use components, spans and Markdown. |
images must stand alone in their paragraph |  inside a sentence. Give it its own paragraph, in a component that takes images. |
attributes are only allowed on spans and inline components | {…} after a link, emphasis or code span. Wrap it in a span: [`code`]{.small}. |
unknown span class ".red" | Not a class in the kit's spans. |
unknown inline component ":note" | Only :button and :link exist. |
Frontmatter
| Message | Cause and fix |
|---|---|
frontmatter: missing "profile" | A required key (template, profile, subject, or a required kit key) is missing. Reported at 1:1. |
frontmatter: template "payout" does not match name "payout.sent" | template must equal the name passed to Compile. |
frontmatter: unknown key "colour" | Neither a core key nor one the kit declares. |
frontmatter: "subject" must be a string | A value of the wrong YAML type. Kit keys also give must be a boolean, must be an integer, must be one of free, pro and must be a list of strings. |
frontmatter: "note" must be one paragraph | An inline key holds one paragraph of Markdown. |
frontmatter: "from" is not a valid address: mail: no angle-addr | A literal from must parse as an address. |
Components
| Message | Cause and fix |
|---|---|
unknown component "callout" | Not a component name or alias of the kit, at the top level or nested in a component that takes no children (unknown component "buton" (did you mean button?)). See Look up the kit's components. |
button: unknown attribute "target" | The schema doesn't declare that key, or it is an #id or .class. |
button: "label" set twice | The same key as an attribute and in the props block. |
button: missing "label" | A required attribute is missing or blank. |
image: alt is required when src is set | A required_with attribute (Quiet). |
image: "width" must be an integer | An int attribute that doesn't parse. |
table: "headless" must be a flag | A flag attribute that isn't bare, true or false (Quiet). |
statement: tone must be "orange" | An enum value outside its values (Quiet). |
progress: "steps" must be literal text | A list attribute can't hold merge tags (Quiet). |
footer: content is not allowed | The component has content: none. |
section: h4 is not allowed here | A block, or a heading level, the component doesn't take. Blockquotes, code blocks and --- rules are never taken. |
column: images are not allowed here | An image in prose needs content.allow: [image]. |
section: list items must be one paragraph | A list item with two paragraphs or a nested list. |
section: image alt text is required | : give the image alt text. |
footer: strikethrough is not allowed | ~~text~~ needs content.inline: [strike], here in an inline attribute. |
section: link titles are not allowed | [text](url "title") needs content.inline: [link_title]. Drop the title. |
notice: 1 to 2 paragraphs, got 3 | A count outside the schema's range (Quiet). |
statement: at most one heading | A max_kind cap (Quiet). |
offer: expected a heading then a paragraph | The content doesn't match the sequence (Quiet). |
breakdown: table must have at most 2 columns, has 3 | A table wider than max_columns (Quiet). It is dropped, so breakdown: expected a table follows. |
columns: 2 to 3 column components, got 1 | The number of children is outside the schema's range. |
columns: only component column is allowed here | Anything but the named child inside a component with children, loose Markdown included. |
column: component columns is not allowed here | A component nested where the parent takes no children. |
image must directly follow a statement | A must_follow rule (Quiet). Move the component. |
Actions
| Message | Cause and fix |
|---|---|
:button must stand alone in its paragraph | A button sharing a paragraph with text. Put it on its own line. |
notice: action row is not allowed here | The component's content doesn't allow actions (Quiet). |
more than one :button in the template | The kit's template-wide limits (Quiet). Keep one :button; make the rest :link. |
letter: :button is not allowed here | The component's own limits (Quiet): use :link, or move the button into a statement or actions. |
:link: missing href | An action without href, or with an empty one. |
:button: missing label | An action in a row with no label. |
:link: label must be plain text | An action label holds emphasis, code or a link. |
Merge tags and bindings
| Message | Cause and fix |
|---|---|
unknown name "hero_url" | The first segment is not a field of your type or of the Recipient. Usually a typo, or a field without the JSON tag you expected. |
unknown field "nme" in quiet.Courier (did you mean courier.name?) | A later segment doesn't exist on that struct. The suggestion is the whole corrected path. |
{{courier}} is quiet.Courier, not a scalar | A tag must end at a string, an integer or a fmt.Stringer. Point it at a field. |
cannot descend into string at "courier.rating" | A path continues past a scalar, a slice or a non-string-keyed map. |
receipt: :order is string, want quiet.Receipt | A binding must resolve to exactly the schema's type. |
receipt: missing binding ":order" | A required binding is missing. |
receipt: :order is untyped data (order), want quiet.Receipt | map[string]any data can't fill a binding. Compile against a struct. |
Know the render-time errors
Errors that depend on data or on the Renderer happen at Render instead. They are *ir.Error values in the same format, with the template's position. These came from lttr lint, which renders a sample, and from test programs:
| Message | Cause and fix |
|---|---|
unknown profile "nope" | profile names no profile of the renderer's Config. |
frontmatter: "from" is not allowed: profile "security" has a fixed From | Remove from, or send under a profile without a From. See Set the sender. |
no value for {{customer.nme}} (did you mean customer.name?) | A tag with no value and no fallback. Add a fallback, or fix the data. With untyped data, a key the value lacks gets a suggestion from the keys it has. |
{{customer}} is map[string]interface {}, not a scalar | Untyped data holds a map or a list where a tag prints. |
merge value {{card}} cannot form part of a url host | A value in a URL host that isn't a single DNS label between // or . and .. |
image: src: url "": empty | A required url attribute evaluated to nothing. |
section: link: url "javascript:alert(1)": scheme "javascript" not allowed | A URL with a scheme other than https, http, mailto or tel. |
progress: components/progress/html.tmpl:2:11: error calling progress: current "Three" is not a step | A rule the kit checks in its own template code (Quiet): the message names the kit file. |
The last row is a kit template error: a rule the schema can't express, raised by the kit at render (D47). Such an error names the component, then the kit file and position. See Template checking.
Next steps
- Comark syntax for the rules behind the syntax errors.
- Merge tags and data for path resolution.
- Studio, which shows compile errors in the browser as you edit.
Actions and spans
Buttons, links and styled runs of text — the two built-in inline components, action rows, links in prose and the kit's span classes.
What is a kit
A kit is a directory of YAML and Go templates that gives lttr its look and its components. The files, how Go loads them, and the two kits lttr ships.