siyuan-note/siyuan · error
Field [id] should be of type [String]
Error message
Field [id] should be of type [String]
What it means
The block-info endpoint requires the id field to be a JSON string. The generic decoder would return a raw Go UnmarshalTypeError; this endpoint installs a custom decodeRequest that detects that case for string-typed fields and replaces it with the stable, human-readable message 'Field [id] should be of type [String]' for backward compatibility.
Solutions
- Send id as a quoted JSON string: {"id":"20240101120000-abcdefg"}.
- Coerce numeric-looking IDs to strings on the client before sending (String(id)).
- Check where the ID originates (DB row, CSV) and ensure it is kept as text end-to-end.
- If the error persists, print the raw request body to confirm the JSON type of id.
Example fix
// before
{"id": 20240101120000}
// after
{"id": "20240101120000-abcdefg"} Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof payload.id !== "string") { payload.id = String(payload.id); } Type guard
const isBlockId = (v) => typeof v === "string" && v.length > 0;
Try / catch
try {
await post("/api/block/getBlockInfo", {id});
} catch (e) {
if (String(e.message).includes("Field [id] should be of type [String]")) {
await post("/api/block/getBlockInfo", {id: String(id)});
} else { throw e; }
} Prevention
- Keep block IDs as strings from source (DB, CSV) to send
- Never let CSV/spreadsheet importers coerce all-digit IDs to numbers
- Add a runtime typeof check at the API client boundary
- Log the payload when this error occurs to spot coercion sources
When it happens
Trigger: POSTing to /api/block/getBlockInfo with {"id":12345} (numeric ID), {"id":true}, or an object/array instead of a quoted block ID string.
Common situations: Numeric IDs coming from databases or spreadsheet data, JS clients that strip quotes via template/eval mistakes, or copy-pasting a block ID that was accidentally coerced to a number (e.g. an all-digit ID in a weakly typed script).
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
- Field [ ] should be of type [Array]
- Field [ ] should be of type [ ]
- Field [scope] should be of type [String]
- block ID must be text
- block is not a list item
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/a56620899ca5330d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/apicontract/block_info_decode.go:17
package apicontract
import (
"encoding/json"
"errors"
"io"
"reflect"
)
func init() {
endpoint := GetBlockInfo
GetBlockInfo.decodeRequest = func(reader io.Reader) (BlockInfoRequest, error) {
request, err := endpoint.Decode(reader)
var typeError *json.UnmarshalTypeError
// 块信息入口保留 ID 类型错误的既有消息。
if errors.As(err, &typeError) && typeError.Type.Kind() == reflect.String {
return request, errors.New("Field [id] should be of type [String]")
}
return request, err
}
}
View on GitHub (pinned to 9f775e8a12)