siyuan-note/siyuan · error

inline style must not be null

Error message

inline style must not be null

What it means

normalizeInlineStyles validates every element of the custom inline style list passed to setInlineStylesData (backing SetInlineStyles, SetInlineStylesData, SetWorkspaceAVPalette) and loadInlineStyles. A nil *InlineStyle element in the slice cannot carry an ID, name, or themes, so the kernel rejects the whole list before any normalization or persistence occurs. The save is aborted atomically: nothing is written to the inline styles JSON.

Solutions

  1. Remove the nil element from the []*InlineStyle slice before calling SetInlineStyles / SetInlineStylesData
  2. When constructing the slice, use append instead of pre-sized make() so no nil slots remain
  3. Fix the inline styles JSON on disk (remove the null array entry) if the error comes from loadInlineStyles
  4. Iterate the incoming array and skip-or-fail null entries in the caller before invoking the API

Example fix

// before
styles := make([]*InlineStyle, 3)
styles[0] = s1; styles[2] = s3 // styles[1] is nil
SetInlineStyles(styles) // -> "inline style must not be null"
// after
styles := []*InlineStyle{s1, s2, s3} // all entries non-nil
SetInlineStyles(styles)
Defensive patterns

Strategy: validation

Validate before calling

func hasNoNilStyles(styles []*InlineStyle) bool {
	for _, s := range styles {
		if s == nil {
			return false
		}
	}
	return true
}

Type guard

func validStyle(s *InlineStyle) bool { return s != nil }

Try / catch

ret, _, err := model.SetInlineStyles(styles)
if err != nil {
	if strings.Contains(err.Error(), "must not be null") {
		// sanitize: drop nil entries and retry once
	}
	return err
}

Prevention

When it happens

Trigger: Passing a []*InlineStyle containing a nil element to model.SetInlineStyles or model.SetInlineStylesData; decoding the styles JSON where a styles[] entry is JSON null; building the slice programmatically with a placeholder nil slot left in place; loadInlineStyles reading a hand-edited or partially written inline styles config file that contains a null array entry.

Common situations: Frontend/automation code appending a new style by pushing to an array that still contains an uninitialized entry; JSON unmarshalling of a config where a null literal was left in the styles array after manual editing; Go code doing `styles := make([]*InlineStyle, n)` and filling only some indices.

Related errors


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

Appendix: source

Thrown at kernel/model/inline_style.go:651

		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) {
			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{}{}

View on GitHub (pinned to 9f775e8a12)