{"record":{"id":"a7eca71aeb3dbb14","repo":"siyuan-note/siyuan","slug":"invalid-petaldisabled","errorCode":null,"errorMessage":"invalid petalDisabled","messagePattern":"invalid petalDisabled","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/apicontract/setting_config.go","lineNumber":115,"sourceCode":"}\ntype SettingEmojiRequest struct {\n\tEmoji []string `json:\"emoji\"`\n}\ntype SettingThemeRequest struct {\n\tTheme          string    `json:\"theme\" api:\"optional,nullable\"`\n\tModes          []float64 `json:\"modes\" api:\"optional,nullable\"`\n\tAppearanceMode string    `json:\"appearanceMode\" api:\"optional,nullable\"`\n}\n\nfunc init() {\n\tSetBazaarPetalDisabled.decodeRequest = func(reader io.Reader) (r SettingPetalDisabledRequest, err error) {\n\t\tfields, err := blockRequestFields(reader, SetBazaarPetalDisabled.Definition().Path)\n\t\tif err != nil {\n\t\t\treturn r, err\n\t\t}\n\t\tr.PetalDisabled, err = legacyField[bool](fields, \"petalDisabled\", \"Boolean\", true)\n\t\tif err != nil {\n\t\t\terr = errors.New(\"invalid petalDisabled\")\n\t\t}\n\t\treturn\n\t}\n\tSetTheme.decodeRequest = func(reader io.Reader) (r SettingThemeRequest, err error) {\n\t\tfields, err := blockRequestFields(reader, SetTheme.Definition().Path)\n\t\tif err != nil {\n\t\t\treturn r, err\n\t\t}\n\t\tif r.Theme, err = legacyField[string](fields, \"theme\", \"String\", false); err != nil {\n\t\t\treturn\n\t\t}\n\t\tmodes, err := legacyField[[]json.RawMessage](fields, \"modes\", \"Array\", false)\n\t\tif err != nil {\n\t\t\treturn r, err\n\t\t}\n\t\tif r.AppearanceMode, err = legacyField[string](fields, \"appearanceMode\", \"String\", false); err != nil {\n\t\t\treturn\n\t\t}","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/apicontract/setting_config.go#L97-L133","documentation":"The SetBazaarPetalDisabled request decoder reads the boolean field 'petalDisabled' via legacyField[bool] and, if that typed extraction fails (missing, wrong type, or null when required), replaces the error with 'invalid petalDisabled'. It guards the typed contract of the petalDisabled flag.","triggerScenarios":"Calling the bazaar petal-disabled endpoint with petalDisabled absent, set to a non-boolean (string \"true\", number), or JSON null when a Boolean is required.","commonSituations":"Plugins/scripts sending truthy/falsy JS values serialized as strings, older API clients using 0/1 integers, or omitting the field assuming a default.","solutions":["Send petalDisabled as a JSON boolean: true or false","Check typeof petalDisabled === 'boolean' before sending","Omit coercion: don't send \"true\"/0/null","Consult the endpoint contract in kernel/apicontract for the exact field type"],"exampleFix":"// before\nbody: JSON.stringify({ petalDisabled: 'true' })\n// after\nbody: JSON.stringify({ petalDisabled: true })","handlingStrategy":"type-guard","validationCode":"function assertPetalDisabled(v: unknown): boolean {\n  if (typeof v !== 'boolean') throw new Error('petalDisabled must be a boolean');\n  return v;\n}","typeGuard":"function isBoolean(v: unknown): v is boolean { return typeof v === 'boolean'; }","tryCatchPattern":"try { await setBazaarPetalDisabled(flag); } catch (e) { if (String(e).includes('invalid petalDisabled')) { flag = Boolean(flag); retry(); } }","preventionTips":["Serialize booleans as JSON true/false, never \"true\"/0","Use TypeScript's boolean type to catch coercion at compile time","Avoid relying on falsy defaults; always send the explicit boolean","Check the petal API contract for field types"],"tags":["validation","json","type-mismatch"],"backgroundTag":"type-mismatch","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"}