siyuan-note/siyuan · error

invalid inline style ID

Error message

invalid inline style ID [%s]

What it means

Each custom inline style must have an ID matching the SiYuan node-ID pattern (ast.IsNodeIDPattern, e.g. 14-digit timestamp-based IDs). After optional auto-generation (only when generateIDs is true and the ID is empty), a non-empty ID that does not match the pattern causes the entire save/load to be rejected. This guarantees style IDs can be referenced as valid node IDs in document spans.

Solutions

  1. Assign each style an ID produced by ast.NewNodeID() (14-digit node-ID format) before saving, or leave the ID empty so generateIDs mints one
  2. Trim surrounding whitespace from the ID; only whitespace is tolerated (TrimSpace) — other characters are not
  3. If the error arises on load, correct the malformed ID in the inline styles JSON to a valid node-ID pattern value
  4. Do not reuse block IDs from other systems; use the kernel's ID generator

Example fix

// before
style := &InlineStyle{ID: "my-style", Name: "Mark"}
SetInlineStyles([]*InlineStyle{style}) // -> invalid inline style ID [my-style]
// after
style := &InlineStyle{ID: ast.NewNodeID(), Name: "Mark"}
SetInlineStyles([]*InlineStyle{style})
Defensive patterns

Strategy: validation

Validate before calling

func hasValidStyleIDs(styles []*InlineStyle) bool {
	for _, s := range styles {
		id := strings.TrimSpace(s.ID)
		if id == "" || !ast.IsNodeIDPattern(id) {
			return false
		}
	}
	return true
}

Type guard

func hasNodeID(s *InlineStyle) bool { return ast.IsNodeIDPattern(strings.TrimSpace(s.ID)) }

Try / catch

ret, _, err := model.SetInlineStyles(styles)
if err != nil {
	var msg string
	if _, scan := fmt.Sscanf(err.Error(), "invalid inline style ID %s", &msg); scan == nil {
		// regenerate offending ID via ast.NewNodeID() and retry
	}
	return err
}

Prevention

When it happens

Trigger: Calling model.SetInlineStyles / model.SetInlineStylesData with a style whose ID is an arbitrary string like "style-1", a UUID, or whitespace-only while generateIDs is false; loading an inline styles config whose styles[] entry has a malformed ID (truncated, hand-crafted, or from an older/other format); an empty ID when generateIDs is false.

Common situations: External tools or sync merges writing style IDs that were never minted by ast.NewNodeID; hand-editing the JSON config; copying a style entry and mangling the ID; calling the API with a client-generated short slug instead of a node ID.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/inline_style.go:664

	}
	ret = make([]*InlineStyle, 0, len(styles))
	ids := make(map[string]struct{}, len(styles))
	for _, style := range styles {
		if style == nil {
			return nil, errors.New("inline style must not be null")
		}

		id := strings.TrimSpace(style.ID)
		if id == "" && generateIDs {
			for {
				id = ast.NewNodeID()
				if _, exists := ids[id]; !exists {
					break
				}
			}
		}
		if !ast.IsNodeIDPattern(id) {
			return nil, fmt.Errorf("invalid inline style ID [%s]", id)
		}
		if _, exists := ids[id]; exists {
			return nil, fmt.Errorf("duplicate inline style ID [%s]", id)
		}
		ids[id] = struct{}{}

		name := strings.TrimSpace(style.Name)
		if name == "" {
			return nil, errors.New("inline style name must not be empty")
		}
		if maxInlineStyleNameRunes < utf8.RuneCountInString(name) {
			return nil, fmt.Errorf("inline style name exceeds the %d character limit", maxInlineStyleNameRunes)
		}
		if style.Light == nil || style.Dark == nil {
			return nil, fmt.Errorf("inline style [%s] must define light and dark themes", id)
		}

		light, err := normalizeInlineStyleTheme(style.Light)

View on GitHub (pinned to 9f775e8a12)