{"record":{"id":"cff21365a5dbb98d","repo":"siyuan-note/siyuan","slug":"parses-request-s-failed-s-setting-config","errorCode":null,"errorMessage":"Parses request [%s] failed: %s","messagePattern":"Parses request \\[(.+?)\\] failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/apicontract/setting_config.go","lineNumber":34,"sourceCode":"\tconfigError error\n}\n\nfunc (r settingConfig) ConfigJSON() []byte        { return append([]byte(nil), r.raw...) }\nfunc (r settingConfig) ConfigError() error        { return r.configError }\nfunc (r settingConfig) HasField(name string) bool { _, ok := r.fields[name]; return ok }\n\nfunc decodeSettingConfig(reader io.Reader, path string, removeApp bool) (r settingConfig, err error) {\n\tvar raw json.RawMessage\n\terr = json.NewDecoder(reader).Decode(&raw)\n\tif err == nil {\n\t\tr.fields, err = legacyJSONValue[map[string]json.RawMessage](raw)\n\t}\n\tif err != nil {\n\t\tif errors.Is(err, io.EOF) {\n\t\t\terr = errors.New(\"the request body is empty or truncated (EOF)\")\n\t\t}\n\t\tdetail := strings.ReplaceAll(err.Error(), \"map[string]json.RawMessage\", \"map[string]interface {}\")\n\t\terr = fmt.Errorf(\"Parses request [%s] failed: %s\", path, detail)\n\t\treturn\n\t}\n\tif removeApp {\n\t\tdelete(r.fields, \"app\")\n\t}\n\tr.raw, err = json.Marshal(r.fields)\n\treturn\n}\n\nfunc settingConfigError(err error) error {\n\tif err == nil {\n\t\treturn nil\n\t}\n\tmessage := strings.ReplaceAll(err.Error(), \"apicontract.Setting\", \"conf.\")\n\tmessage = strings.ReplaceAll(message, \"field Setting\", \"field \")\n\tfor _, name := range []string{\"Markdown\", \"StatusBar\", \"Notifications\"} {\n\t\tmessage = strings.ReplaceAll(message, \"conf.\"+name, \"util.\"+name)\n\t}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/apicontract/setting_config.go#L16-L52","documentation":"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).","triggerScenarios":"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.","commonSituations":"Hand-written curl with unquoted JSON, clients sending duplicated form fields, encoding issues (UTF-8 BOM), or schema drift after an API version change.","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"],"exampleFix":"// before\nbody: '{name: }' // invalid JSON\n// after\nbody: JSON.stringify({ name: 'value' })","handlingStrategy":"validation","validationCode":"function assertValidJson(body: string): Record<string, unknown> {\n  const parsed = JSON.parse(body);\n  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) throw new Error('body must be a JSON object');\n  return parsed;\n}","typeGuard":"function isJsonObject(v: unknown): v is Record<string, unknown> { return typeof v === 'object' && v !== null && !Array.isArray(v); }","tryCatchPattern":"try { await post(url, body); } catch (e) { if (String(e).startsWith('Parses request [')) { console.error('bad payload', body); } }","preventionTips":["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"],"tags":["http","json","request-parsing"],"backgroundTag":"json-parse-error","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}