siyuan-note/siyuan · error

inline styles must not be null

Error message

inline styles must not be null

What it means

setInlineStylesData rejects a nil *InlineStyles pointer before doing any work. The kernel stores workspace inline styles (including attribute-view palettes) as a versioned JSON document, and mutating that document requires a non-nil input struct. Callers that pass nil (e.g. decoding a missing/empty payload into a nil pointer) hit this guard immediately.

Solutions

  1. Ensure the request payload contains a valid inline styles JSON object so it decodes into a non-nil *InlineStyles.
  2. If starting from scratch, create an empty styles value (e.g. &model.InlineStyles{Version: model.InlineStylesVersion, Styles: ...}) instead of passing nil.
  3. Add a nil check in the calling code before invoking SetInlineStyles/SetInlineStylesData and return a client-side validation error.

Example fix

// before
var styles *model.InlineStyles
ret, changed, err := model.SetInlineStylesData(styles)
// after
styles := &model.InlineStyles{Version: model.InlineStylesVersion}
ret, changed, err := model.SetInlineStylesData(styles)
Defensive patterns

Strategy: type-guard

Validate before calling

if styles == nil {
    return errors.New("inline styles payload is required")
}

Type guard

func isValidInlineStyles(s *model.InlineStyles) bool { return s != nil }

Prevention

When it happens

Trigger: Calling SetInlineStyles / SetInlineStylesData with a nil styles argument, or SetWorkspaceAVPalette / replaceWorkspaceAVPalette when the loaded or decoded InlineStyles is nil (e.g. unmarshalling an absent or invalid JSON body leaves the pointer nil).

Common situations: An HTTP request body that is empty or fails to decode into *InlineStyles, an API client omitting the styles field entirely, or plugin/binding code constructing the call without initializing the struct.

Related errors


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

Appendix: source

Thrown at kernel/model/inline_style.go:231

			})
		}
		filteredHidden := current.Builtin.Hidden.AV[:0]
		for _, index := range current.Builtin.Hidden.AV {
			if index != patch.Index {
				filteredHidden = append(filteredHidden, index)
			}
		}
		current.Builtin.Hidden.AV = filteredHidden
		if patch.Hidden {
			current.Builtin.Hidden.AV = append(current.Builtin.Hidden.AV, patch.Index)
		}
	}
	return setInlineStylesData(current, currentAV)
}

func setInlineStylesData(styles *InlineStyles, currentAV *InlineStyleAV) (ret *InlineStyles, changed bool, err error) {
	if styles == nil {
		return nil, false, errors.New("inline styles must not be null")
	}
	if styles.Version != InlineStylesVersion {
		return nil, false, fmt.Errorf("unsupported inline styles version [%d]", styles.Version)
	}
	if currentAV == nil {
		currentAV = newEmptyInlineStyleAV()
	}

	normalizedStyles, err := normalizeInlineStyles(styles.Styles, true)
	if err != nil {
		return nil, false, err
	}
	normalizedBuiltin, err := normalizeInlineStyleBuiltin(styles.Builtin)
	if err != nil {
		return nil, false, err
	}
	normalizedAV, err := normalizeInlineStyleAV(styles.AV, true)
	if err != nil {

View on GitHub (pinned to 9f775e8a12)