Wei-Shaw/sub2api · error
proxies is required
Error message
proxies is required
What it means
Returned by validateDataHeader (backend/internal/handler/admin/account_data.go:646) when an imported/exported data payload omits the top-level "proxies" key entirely (payload.Proxies == nil). Because Go cannot distinguish an absent array from an empty one with a plain slice, the field must be present — an empty array [] is valid, but a missing key is not. Type and version header checks run before this.
Source
Thrown at backend/internal/handler/admin/account_data.go:646
switch raw {
case "1", "true", "yes", "on":
return true, nil
case "0", "false", "no", "off":
return false, nil
default:
return true, fmt.Errorf("invalid include_proxies value: %s", raw)
}
}
func validateDataHeader(payload DataPayload) error {
if payload.Type != "" && payload.Type != dataType && payload.Type != legacyDataType {
return fmt.Errorf("unsupported data type: %s", payload.Type)
}
if payload.Version != 0 && payload.Version != dataVersion {
return fmt.Errorf("unsupported data version: %d", payload.Version)
}
if payload.Proxies == nil {
return errors.New("proxies is required")
}
if payload.Accounts == nil {
return errors.New("accounts is required")
}
return nil
}
func validateDataProxy(item DataProxy) error {
if strings.TrimSpace(item.Protocol) == "" {
return errors.New("proxy protocol is required")
}
if strings.TrimSpace(item.Host) == "" {
return errors.New("proxy host is required")
}
if item.Port <= 0 || item.Port > 65535 {
return errors.New("proxy port is invalid")
}
switch item.Protocol {View on GitHub (pinned to 073e92d171)
Solutions
- Add "proxies": [] (or your proxy list) to the top level of the payload.
- If generating the JSON programmatically, remove omitempty from the Proxies field or always emit an empty array.
- Validate the payload shape client-side before submitting.
Example fix
// before
{ "type": "data", "version": 1, "accounts": [ ... ] }
// after
{ "type": "data", "version": 1, "proxies": [], "accounts": [ ... ] } Defensive patterns
Strategy: validation
Validate before calling
function hasProxiesKey(payload: unknown): boolean {
return typeof payload === 'object' && payload !== null && 'proxies' in payload && Array.isArray((payload as any).proxies)
} Type guard
function isShapedDataPayload(p: unknown): p is { proxies: unknown[]; accounts?: unknown[] } {
return typeof p === 'object' && p !== null && Array.isArray((p as { proxies?: unknown }).proxies)
} Prevention
- Always emit both top-level arrays in generated payloads, even when empty.
- Remove omitempty from Proxies/Accounts in Go structs used for export.
- Schema-check payloads client-side (presence of proxies and accounts keys) before upload.
When it happens
Trigger: POSTing an account/proxy data-import JSON that has "accounts" but no "proxies" key at all; hand-writing a payload and forgetting the proxies array; a client serializer that omits empty arrays (omitempty on a nil slice).
Common situations: Custom export scripts using Go's json.Marshal with omitempty dropping empty proxies; hand-crafted minimal import payloads; third-party tools generating the format without reading the schema.
Related errors
- accounts is required
- 空 JSON 内容
- agent identity 缺少必要字段
- agent identity private key 格式无效
- 缺少 accessToken/access_token
AI-assisted analysis of Wei-Shaw/sub2api@073e92d171 (2026-08-15).
Data as JSON: /api/errors/863a8121d1fc5c4e.
Report an issue: GitHub.