siyuan-note/siyuan · error
Field [ ] is required
Error message
Field [%s] is required
What it means
The checkBlockRef decoder's readArray helper treats a missing key or an explicit JSON null for a required field as an error: 'Field [key] is required'. Required id-array fields must be present and non-null; empty arrays may additionally be rejected when the nonempty flag is set.
Solutions
- Include the required field as a JSON array in the body, e.g. {"ids":["20240101120000-abcdefg"]}.
- Replace null with an empty array if an empty set is acceptable, or omit the call when there is nothing to check.
- Fix client serialization so undefined/None fields are dropped or defaulted, not sent as null.
- Check the endpoint's current contract — the field may have become required after an update.
Example fix
// before
{"ids": null}
// after
{"ids": ["20240101120000-abcdefg", "20240101120000-hijklmn"]} Defensive patterns
Strategy: validation
Validate before calling
const required = ["ids"];
for (const k of required) {
if (!Array.isArray(payload[k])) { throw new Error(`field ${k} must be present and an array`); }
} Type guard
const isPresentArray = (v) => Array.isArray(v);
Try / catch
try {
await post("/api/block/checkBlockRef", payload);
} catch (e) {
const m = String(e.message).match(/Field \[(\w+)\] is required/);
if (m) { payload[m[1]] = payload[m[1]] ?? []; await post("/api/block/checkBlockRef", payload); }
else { throw e; }
} Prevention
- Configure serializers to drop undefined instead of emitting null
- Always initialize required array fields to [] before building the payload
- Schema-validate payloads against the endpoint contract in CI
- Re-check field requirements after API version upgrades
When it happens
Trigger: POSTing to /api/block/checkBlockRef without the ids field ({}) , with {"ids":null}, or omitting another required array field the decoder asks for via readArray(key, true, ...).
Common situations: Clients serializing undefined values as null (JSON.stringify drops undefined but libraries often emit null), payloads built conditionally where the field was skipped, or API version drift where a formerly optional field became required.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- element [ ]
- empty JSON value
- entry [ ]
- Field [conf] should be of type [Object]
- Field [ ] has an invalid constant
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/206f7549cb24bb91.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/apicontract/block_remaining.go:85
fields, err := blockRequestFields(reader, "/api/block/checkBlockRef")
if err != nil {
return request, err
}
if raw, present := fields["scope"]; present {
if bytes.Equal(raw, []byte("null")) || json.Unmarshal(raw, &request.Scope) != nil {
return request, errors.New("Field [scope] should be of type [String]")
}
}
if strings.TrimSpace(request.Scope) == "" {
request.Scope = "blocks"
}
readArray := func(key string, required, nonempty bool) ([]string, error) {
raw, present := fields[key]
if !present && !required {
return nil, nil
}
if !present || bytes.Equal(raw, []byte("null")) {
return nil, fmt.Errorf("Field [%s] is required", key)
}
var entries []json.RawMessage
if json.Unmarshal(raw, &entries) != nil {
return nil, fmt.Errorf("Field [%s] should be of type [Array]", key)
}
if nonempty && len(entries) == 0 {
return nil, fmt.Errorf("Field [%s] must not be empty", key)
}
var values []string
seen := map[string]bool{}
for _, entry := range entries {
var value string
if json.Unmarshal(entry, &value) != nil || strings.TrimSpace(value) == "" {
return nil, fmt.Errorf("Field [%s] should contain non-empty strings", key)
}
if !seen[value] {
values = append(values, value)
seen[value] = trueView on GitHub (pinned to 9f775e8a12)