siyuan-note/siyuan · error

invalid template document attributes

Error message

invalid template document attributes

What it means

applyTemplateDocumentAttributes processes a fenced code block whose info string is the marker `siyuan-template-doc-attrs-v1`; the fenced body must be a document-attribute IAL of the form {: ... type="doc" ...}. This error is thrown when the fence block has no code-content child node, meaning the marker block is structurally malformed in the parsed tree.

Solutions

  1. Open the template file and locate the ```siyuan-template-doc-attrs-v1 fenced block
  2. Ensure the block body contains a valid attribute line such as {: type="doc" name="value"}
  3. Remove the marker block entirely if no document attributes are needed
  4. Re-save the template ensuring the fence content is not stripped or left empty

Example fix

// before
```siyuan-template-doc-attrs-v1
```
// after
```siyuan-template-doc-attrs-v1
{: type="doc" title="Weekly"}
```
Defensive patterns

Strategy: validation

Validate before calling

// assert marker fence has a body: between ```siyuan-template-doc-attrs-v1 and closing fence there must be a {: ... } line

Try / catch

if err := applyTemplateDocumentAttributes(tree); err != nil { return fmt.Errorf("invalid doc attrs block: %w", err) }

Prevention

When it happens

Trigger: Raised from applyTemplateDocumentAttributes (called by parseTemplateKTree) when a code block marked with siyuan-template-doc-attrs-v1 exists but node.ChildByType(ast.NodeCodeBlockCode) is nil — i.e. the fenced block carries the marker info string yet contains no code body node.

Common situations: A template containing an empty or corrupted ```siyuan-template-doc-attrs-v1 fence, or a fence whose content was lost by an editor/export round-trip that stripped the code body.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/ea01670c060218fe. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template_export_attrs.go:51

	if tree == nil {
		return nil, errors.New("parse template tree failed")
	}
	normalizeTree(tree)
	if err := applyTemplateDocumentAttributes(tree); err != nil {
		return nil, err
	}
	return tree, nil
}

// 独立文档属性保留在原位置求值,渲染完成后再合并到根节点。
func applyTemplateDocumentAttributes(tree *parse.Tree) error {
	for node := tree.Root.FirstChild; node != nil; {
		next := node.Next
		info := node.ChildByType(ast.NodeCodeBlockFenceInfoMarker)
		if node.Type == ast.NodeCodeBlock && info != nil && string(info.CodeBlockInfo) == templateDocumentAttributeMarker {
			code := node.ChildByType(ast.NodeCodeBlockCode)
			if code == nil {
				return errors.New("invalid template document attributes")
			}
			source := strings.TrimSpace(string(code.Tokens))
			attrs := parseTemplateDocumentAttributes(source)
			if len(attrs) == 0 {
				return errors.New("invalid template document attributes")
			}
			for _, attr := range attrs {
				if attr[0] == "id" || attr[0] == "updated" {
					continue
				}
				tree.Root.RemoveIALAttr(attr[0])
				tree.Root.KramdownIAL = append(tree.Root.KramdownIAL, attr)
			}
			if next != nil && next.Type == ast.NodeKramdownBlockIAL && parse.IAL2Map(parse.Tokens2IAL(next.Tokens))["type"] != "doc" {
				ial := next
				next = next.Next
				ial.Unlink()
			}

View on GitHub (pinned to 9f775e8a12)