siyuan-note/siyuan · error
Parses request [ ] failed
Error message
Parses request [%s] failed: %s
What it means
decodeSettingConfig wraps any body-decoding failure in 'Parses request [%s] failed: %s', where %s is the endpoint path and the underlying decode error. It is the generic envelope for malformed JSON or wrong JSON shapes on setting config endpoints (after the special-cased EOF message).
Solutions
- Validate the JSON body parses and is a top-level object before sending
- Read the detail portion of the message for the exact JSON syntax/shape error
- Re-send with Content-Type: application/json
- Compare against the endpoint's documented contract in kernel/apicontract
Example fix
// before
body: '{name: }' // invalid JSON
// after
body: JSON.stringify({ name: 'value' }) Defensive patterns
Strategy: validation
Validate before calling
function assertValidJson(body: string): Record<string, unknown> {
const parsed = JSON.parse(body);
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) throw new Error('body must be a JSON object');
return parsed;
} Type guard
function isJsonObject(v: unknown): v is Record<string, unknown> { return typeof v === 'object' && v !== null && !Array.isArray(v); } Try / catch
try { await post(url, body); } catch (e) { if (String(e).startsWith('Parses request [')) { console.error('bad payload', body); } } Prevention
- JSON.stringify the payload; never hand-build JSON strings
- Strip UTF-8 BOM before sending
- Test payloads in a JSON linter when debugging
- Keep client payloads in sync with the apicontract definitions
When it happens
Trigger: Sending syntactically invalid JSON, a non-object JSON value (array, string, number), or a body that fails to decode into map[string]json.RawMessage to any setting config endpoint handled by decodeSettingConfig.
Common situations: Hand-written curl with unquoted JSON, clients sending duplicated form fields, encoding issues (UTF-8 BOM), or schema drift after an API version change.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- map[string]json.RawMessage
- Parses request [ ] failed
- Parses request [ ] failed
- Parses request [ ] failed
- the request body is empty or truncated (EOF)
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/cff21365a5dbb98d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/apicontract/setting_config.go:34
configError error
}
func (r settingConfig) ConfigJSON() []byte { return append([]byte(nil), r.raw...) }
func (r settingConfig) ConfigError() error { return r.configError }
func (r settingConfig) HasField(name string) bool { _, ok := r.fields[name]; return ok }
func decodeSettingConfig(reader io.Reader, path string, removeApp bool) (r settingConfig, err error) {
var raw json.RawMessage
err = json.NewDecoder(reader).Decode(&raw)
if err == nil {
r.fields, err = legacyJSONValue[map[string]json.RawMessage](raw)
}
if err != nil {
if errors.Is(err, io.EOF) {
err = errors.New("the request body is empty or truncated (EOF)")
}
detail := strings.ReplaceAll(err.Error(), "map[string]json.RawMessage", "map[string]interface {}")
err = fmt.Errorf("Parses request [%s] failed: %s", path, detail)
return
}
if removeApp {
delete(r.fields, "app")
}
r.raw, err = json.Marshal(r.fields)
return
}
func settingConfigError(err error) error {
if err == nil {
return nil
}
message := strings.ReplaceAll(err.Error(), "apicontract.Setting", "conf.")
message = strings.ReplaceAll(message, "field Setting", "field ")
for _, name := range []string{"Markdown", "StatusBar", "Notifications"} {
message = strings.ReplaceAll(message, "conf."+name, "util."+name)
}View on GitHub (pinned to 9f775e8a12)