siyuan-note/siyuan · error
invalid petalDisabled
Error message
invalid petalDisabled
What it means
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.
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
Example fix
// before
body: JSON.stringify({ petalDisabled: 'true' })
// after
body: JSON.stringify({ petalDisabled: true }) Defensive patterns
Strategy: type-guard
Validate before calling
function assertPetalDisabled(v: unknown): boolean {
if (typeof v !== 'boolean') throw new Error('petalDisabled must be a boolean');
return v;
} Type guard
function isBoolean(v: unknown): v is boolean { return typeof v === 'boolean'; } Try / catch
try { await setBazaarPetalDisabled(flag); } catch (e) { if (String(e).includes('invalid petalDisabled')) { flag = Boolean(flag); retry(); } } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Plugins/scripts sending truthy/falsy JS values serialized as strings, older API clients using 0/1 integers, or omitting the field assuming a default.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- createDocTree definition must be a list
- createDocTree document must be a dictionary
- Field [rootIDs] should be of type [Array]
- Field [ ] has an invalid type
- Field [ ] should be of type [Array]
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/a7eca71aeb3dbb14.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/apicontract/setting_config.go:115
}
type SettingEmojiRequest struct {
Emoji []string `json:"emoji"`
}
type SettingThemeRequest struct {
Theme string `json:"theme" api:"optional,nullable"`
Modes []float64 `json:"modes" api:"optional,nullable"`
AppearanceMode string `json:"appearanceMode" api:"optional,nullable"`
}
func init() {
SetBazaarPetalDisabled.decodeRequest = func(reader io.Reader) (r SettingPetalDisabledRequest, err error) {
fields, err := blockRequestFields(reader, SetBazaarPetalDisabled.Definition().Path)
if err != nil {
return r, err
}
r.PetalDisabled, err = legacyField[bool](fields, "petalDisabled", "Boolean", true)
if err != nil {
err = errors.New("invalid petalDisabled")
}
return
}
SetTheme.decodeRequest = func(reader io.Reader) (r SettingThemeRequest, err error) {
fields, err := blockRequestFields(reader, SetTheme.Definition().Path)
if err != nil {
return r, err
}
if r.Theme, err = legacyField[string](fields, "theme", "String", false); err != nil {
return
}
modes, err := legacyField[[]json.RawMessage](fields, "modes", "Array", false)
if err != nil {
return r, err
}
if r.AppearanceMode, err = legacyField[string](fields, "appearanceMode", "String", false); err != nil {
return
}View on GitHub (pinned to 9f775e8a12)