siyuan-note/siyuan · error

inline styles count exceeds the

Error message

inline styles count exceeds the %d item limit

What it means

normalizeInlineStyles enforces a maximum number of custom inline styles (maxInlineStyles). When the supplied styles array is longer, the kernel rejects it rather than truncating. It is raised both when loading a file with too many entries and when saving (setInlineStylesData) with too many submitted styles.

Solutions

  1. Reduce the styles array to at most maxInlineStyles entries before saving
  2. Deduplicate identical styles (same id/colors) to cut the count
  3. Split rarely used styles out and delete the file if regeneration from defaults is acceptable

Example fix

// before: POST SetInlineStylesData with styles.length > maxInlineStyles
{"styles": [ ...1000 items... ]}
// after
{"styles": styles.slice(0, maxInlineStyles)}
Defensive patterns

Strategy: validation

Validate before calling

if (styles.length > maxInlineStyles) {
  styles = dedupeById(styles).slice(0, maxInlineStyles);
}

Try / catch

try {
  await fetchPost('/api/attr/setInlineStylesData', {styles});
} catch (e) {
  if (String(e).includes('count exceeds')) {
    logging.warn('too many inline styles; trim the list before saving');
  }
}

Prevention

When it happens

Trigger: Calling SetInlineStyles/SetInlineStylesData with a styles array exceeding maxInlineStyles, or loading an inline styles file that contains more than the limit.

Common situations: Importing a styles collection from another workspace, a sync/merge bug duplicating entries, or scripted bulk generation of custom styles.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/inline_style.go:645

	hidden := map[int]struct{}{}
	for _, index := range styles.Builtin.Hidden.AV {
		hidden[index] = struct{}{}
	}
	ret := make([]int, 0, neutralAVColorIndex)
	for index := minBuiltinColorIndex; index <= neutralAVColorIndex; index++ {
		if _, ok := hidden[index]; !ok {
			ret = append(ret, index)
		}
	}
	if len(ret) == 0 {
		return []int{neutralAVColorIndex}
	}
	return ret
}

func normalizeInlineStyles(styles []*InlineStyle, generateIDs bool) (ret []*InlineStyle, err error) {
	if maxInlineStyles < len(styles) {
		return nil, fmt.Errorf("inline styles count exceeds the %d item limit", maxInlineStyles)
	}
	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) {

View on GitHub (pinned to 9f775e8a12)