siyuan-note/siyuan · error

inline style name must not be empty

Error message

inline style name must not be empty

What it means

Every custom inline style requires a non-empty, non-whitespace Name; it is the label shown in the style picker UI. normalizeInlineStyles trims the name and rejects the entire save/load when the result is empty, because a nameless style cannot be identified by users.

Solutions

  1. Set a meaningful trimmed Name on every style before saving
  2. In UI code, validate the name input is non-empty before invoking the API
  3. Repair the config JSON by filling in the missing name if the error occurs on load
  4. Default the name from a template (e.g. the color value) when none is provided

Example fix

// before
SetInlineStyles([]*InlineStyle{{ID: id, Name: "", Light: l, Dark: d}})
// -> "inline style name must not be empty"
// after
SetInlineStyles([]*InlineStyle{{ID: id, Name: "Highlight", Light: l, Dark: d}})
Defensive patterns

Strategy: validation

Validate before calling

func allStylesNamed(styles []*InlineStyle) bool {
	for _, s := range styles {
		if strings.TrimSpace(s.Name) == "" {
			return false
		}
	}
	return true
}

Type guard

func hasName(s *InlineStyle) bool { return strings.TrimSpace(s.Name) != "" }

Try / catch

if _, _, err := model.SetInlineStyles(styles); err != nil {
	if strings.Contains(err.Error(), "name must not be empty") {
		// reject the input in the UI before resubmitting
	}
	return err
}

Prevention

When it happens

Trigger: Calling model.SetInlineStyles / model.SetInlineStylesData with a style whose Name is "" or only whitespace; JSON config where the name field was deleted, left as "", or contains only spaces; UI code creating a style before the user typed a name; programmatic style creation that sets only ID/themes.

Common situations: An automation script building styles from a spreadsheet with a blank name cell; a frontend race saving the style dialog before name input completes; sync/merge dropping the name field; hand-edited JSON missing the key.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/inline_style.go:673

		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)
		if err != nil {
			return nil, fmt.Errorf("invalid light theme of inline style [%s]: %w", id, err)
		}
		dark, err := normalizeInlineStyleTheme(style.Dark)
		if err != nil {
			return nil, fmt.Errorf("invalid dark theme of inline style [%s]: %w", id, err)
		}
		lightColor, lightBackground := light.Color != "", light.BackgroundColor != ""
		darkColor, darkBackground := dark.Color != "", dark.BackgroundColor != ""

View on GitHub (pinned to 9f775e8a12)