siyuan-note/siyuan · error

unsupported inline styles version

Error message

unsupported inline styles version

What it means

The inline-styles request decoder in the API contract layer only accepts protocol versions 1 and 2. When the decoded request carries a `version` field with any other value, decoding is aborted and this error is returned before any styles are applied. It exists to reject requests produced by newer (or corrupted/legacy) clients whose payload shape the server cannot safely interpret.

Solutions

  1. Set the request's version field to 1 (legacy []*InlineStyle styles) or 2 (current format).
  2. Update the client so it matches the server's supported protocol version, or upgrade the kernel to accept the newer version.
  3. Inspect the raw request body to confirm the version value is the integer 1 or 2 and not a string or missing field.

Example fix

// before
{"app": "editor", "version": 3, "styles": [...]}  // rejected
// after
{"app": "editor", "version": 2, "styles": [...]}
Defensive patterns

Strategy: validation

Validate before calling

function checkInlineStyleVersion(payload) {
  if (payload.version !== 1 && payload.version !== 2) {
    throw new Error("version must be 1 or 2");
  }
}

Type guard

function hasSupportedVersion(p) { return p.version === 1 || p.version === 2; }

Try / catch

try { await sendRequest(payload); } catch (e) { if (String(e).includes("unsupported inline styles version")) { payload.version = 2; await sendRequest(payload); } else { throw e; } }

Prevention

When it happens

Trigger: Sending a kernel API request whose decoded fields include version != 1 and version != 2 (e.g. version=3 from a newer client, version=0 omitted/default, or a manually crafted payload with a string that decodes to an unexpected value).

Common situations: A frontend or plugin built against a newer inline-styles protocol calls an older kernel; a hand-written HTTP call omits the version field so it defaults to 0; payload got truncated or tampered with in a proxy.

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/e8bbb517d70445ae. Report an issue: GitHub.

Appendix: source

Thrown at kernel/apicontract/inline_style_input.go:72

func init() {
	SetInlineStyles.decodeRequest = func(reader io.Reader) (request SetInlineStylesRequest, err error) {
		fields, err := blockRequestFields(reader, "/api/storage/setInlineStyles")
		if err != nil {
			return request, err
		}
		version, err := legacyField[float64](fields, "version", "Number", true)
		if err != nil {
			return request, err
		}
		if _, err = legacyField[[]json.RawMessage](fields, "styles", "Array", true); err != nil {
			return request, err
		}
		app, err := legacyField[string](fields, "app", "String", false)
		if err != nil {
			return request, err
		}
		if version != 1 && version != 2 {
			return request, errors.New("unsupported inline styles version")
		}
		if version == 1 {
			request.Styles, err = legacyJSONValue[[]*InlineStyle](fields["styles"])
		} else {
			data, marshalErr := json.Marshal(fields)
			if marshalErr != nil {
				return request, marshalErr
			}
			request, err = legacyJSONValue[SetInlineStylesRequest](data)
		}
		request.Version, request.App = version, app
		return
	}
	SetWorkspaceAVPalette.decodeRequest = func(reader io.Reader) (request WorkspaceAVPaletteRequest, err error) {
		fields, err := blockRequestFields(reader, "/api/storage/setWorkspaceAVPalette")
		if err != nil {
			return request, err
		}

View on GitHub (pinned to 9f775e8a12)