siyuan-note/siyuan · error

invalid inline style ID [%s]

Error message

invalid inline style ID [%s]

What it means

Every inline style must carry an ID matching the SiYuan node-ID pattern (ast.IsNodeIDPattern, typically 14 digits + '-' + 7 alphanumeric chars). If the trimmed ID is empty and generateIDs is false, or the provided ID does not match the pattern, normalization fails so that stored style references stay resolvable.

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 8641553a1f)

Solutions

  1. Give the style a valid node-ID-format ID (yyymmddhhmmss-xxxxxxx) or clear the ID and let the system generate one (generateIDs=true path).
  2. Trim the ID — leading/trailing whitespace is trimmed first, but embedded whitespace still fails the pattern.
  3. Regenerate IDs for existing entries with a script that rewrites the inline-styles JSON to valid node IDs.

Example fix

// before
style := &InlineStyle{ID: "highlight-red", Name: "Red"}
// after
style := &InlineStyle{ID: "20240101120000-abcdefg", Name: "Red"} // or ID: "" with generateIDs enabled
Defensive patterns

Strategy: validation

Validate before calling

const idPattern = /^\d{14}-[0-9a-z]{7}$/; for (const s of styles) { if (!idPattern.test(s.ID.trim())) throw new Error(`bad style ID: ${s.ID}`); }

Type guard

const hasValidId = (s: InlineStyle): boolean => /^\d{14}-[0-9a-z]{7}$/.test(s.ID.trim());

Try / catch

try { await saveStyles(styles) } catch (e) { if (/invalid inline style ID/.test(String(e))) { styles = styles.map(s => ({...s, ID: s.ID.trim()})); /* regenerate or fix IDs, then retry */ } }

Prevention

When it happens

Trigger: Calling setInlineStylesData with an InlineStyle whose ID is empty while generateIDs is false, or whose ID is an arbitrary string like "my-style" or contains whitespace/illegal characters; also triggered when loading a config file with hand-made IDs.

Common situations: Custom-style entries created by scripts or plugins using human-friendly slugs instead of node-ID-format IDs; manually editing the inline-styles JSON; older configs written before the ID pattern check was added.

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@8641553a1f (2026-09-11). Data as JSON: /api/errors/2a6aa05c2c793da2. Report an issue: GitHub.