siyuan-note/siyuan · error

Parses request [ ] failed: map[string]json.RawMessage

Error message

Parses request [%s] failed: map[string]json.RawMessage

What it means

This error wraps a JSON body parse failure for bazaar endpoints. The underlying decoder parses the body into map[string]json.RawMessage; this wrapper rewrites the type name in the message from map[string]json.RawMessage back to map[string]interface {} so legacy clients matching on the old message text keep working. The actual cause is malformed or non-object JSON in the request body.

Solutions

  1. Ensure the request body is a single valid JSON object (starts with {), not an array or scalar.
  2. Validate the JSON with a parser/linter before sending.
  3. Check for truncation: streaming, chunked encodings, or proxy stripping that cuts the body off.
  4. If matching the error text in tests, note the type name is normalized to map[string]interface {}.

Example fix

// before
["siyuan-plugin-a", "siyuan-plugin-b"]
// after
{"packageNames": ["siyuan-plugin-a", "siyuan-plugin-b"]}
Defensive patterns

Strategy: try-catch

Validate before calling

let parsed; try { parsed = JSON.parse(bodyString); } catch { throw new Error("body is not valid JSON"); }
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) { throw new Error("body must be a JSON object"); }

Type guard

const isJsonObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);

Try / catch

try {
  await post(path, body);
} catch (e) {
  if (String(e.message).includes("Parses request")) {
    console.error("Non-object or malformed JSON body:", bodyString);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Sending a bazaar API request whose body is not a JSON object (e.g. a JSON array, bare string/number, or invalid JSON), which makes blockRequestFields fail, then surfaced via bazaarRequestFields with the legacy-normalized message.

Common situations: Clients posting arrays of packages instead of an object with a packageNames key, Content-Type/encoding mismatches producing truncated bodies, or tests asserting on the legacy error text.

Related errors


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

Appendix: source

Thrown at kernel/apicontract/bazaar.go:956

			return request, err
		}
		if request.Frontend, err = bazaarString(fields, "frontend", false, false); err != nil {
			return request, err
		}
		if request.Keyword, err = bazaarString(fields, "keyword", false, false); err != nil {
			return request, err
		}
		if request.PackageName, err = bazaarString(fields, "packageName", true, true); err != nil {
			return request, err
		}
		return request, nil
	}
}

func bazaarRequestFields(reader io.Reader, path string) (map[string]json.RawMessage, error) {
	fields, err := blockRequestFields(reader, path)
	if err != nil {
		return nil, errors.New(strings.ReplaceAll(err.Error(), "map[string]json.RawMessage", "map[string]interface {}"))
	}
	return fields, nil
}

View on GitHub (pinned to 9f775e8a12)