siyuan-note/siyuan · error

Field [type] must not be empty

Error message

Field [type] must not be empty

What it means

The graph request decoder requires a `type` field of type String that is non-empty after trimming whitespace. legacyField first enforces presence/type, then the code trims the value and rejects an all-whitespace string. This ensures every graph request names its configuration type explicitly.

Solutions

  1. Include a non-empty "type" field in the request, e.g. {"type": "graph"}
  2. Trim or default the type value in client code before sending
  3. Check that the field key is exactly "type" (case-sensitive)

Example fix

// before
{"type": "", "conf": {}}
// after
{"type": "graph", "conf": {}}
Defensive patterns

Strategy: validation

Validate before calling

if (typeof body.type !== "string" || body.type.trim() === "") {
  throw new Error("type must be a non-empty string");
}

Type guard

const hasNonEmptyString = (o, k) => typeof o[k] === "string" && o[k].trim().length > 0;

Prevention

When it happens

Trigger: Calling the graph set-configuration endpoint with `{}` (missing `type`), with `"type": ""`, or with `"type": " "`. Missing type actually surfaces as 'Field [type] is required' from legacyField; this message appears when type is present but empty/whitespace.

Common situations: Frontend code building the payload dynamically and leaving the type variable unset or empty; API consumers omitting required fields after copying an example.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/76bcf085fec60192. Report an issue: GitHub.

Appendix: source

Thrown at kernel/apicontract/graph_input.go:56

}

type SetGraphConfRequest struct {
	Type string             `json:"type" api:"trim"`
	Conf GraphConfiguration `json:"conf"`
}

func init() {
	SetGraphConf.decodeRequest = func(reader io.Reader) (request SetGraphConfRequest, err error) {
		fields, err := blockRequestFields(reader, "/api/graph/setGraphConf")
		if err != nil {
			return request, err
		}
		if request.Type, err = legacyField[string](fields, "type", "String", true); err != nil {
			return request, err
		}
		request.Type = strings.TrimSpace(request.Type)
		if request.Type == "" {
			return request, fmt.Errorf("Field [type] must not be empty")
		}
		if len(fields["conf"]) == 0 {
			return request, fmt.Errorf("Field [conf] is required")
		}
		err = json.Unmarshal(fields["conf"], &request.Conf)
		return
	}
}

type GraphConfigurationData struct {
	global *GlobalGraphConf
	local  *LocalGraphConf
}

func GlobalGraphConfiguration(value GlobalGraphConf) GraphConfigurationData {
	return GraphConfigurationData{global: &value}
}
func LocalGraphConfiguration(value LocalGraphConf) GraphConfigurationData {

View on GitHub (pinned to 9f775e8a12)