{"record":{"id":"863a8121d1fc5c4e","repo":"Wei-Shaw/sub2api","slug":"proxies-is-required","errorCode":null,"errorMessage":"proxies is required","messagePattern":"proxies is required","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"backend/internal/handler/admin/account_data.go","lineNumber":646,"sourceCode":"\tswitch raw {\n\tcase \"1\", \"true\", \"yes\", \"on\":\n\t\treturn true, nil\n\tcase \"0\", \"false\", \"no\", \"off\":\n\t\treturn false, nil\n\tdefault:\n\t\treturn true, fmt.Errorf(\"invalid include_proxies value: %s\", raw)\n\t}\n}\n\nfunc validateDataHeader(payload DataPayload) error {\n\tif payload.Type != \"\" && payload.Type != dataType && payload.Type != legacyDataType {\n\t\treturn fmt.Errorf(\"unsupported data type: %s\", payload.Type)\n\t}\n\tif payload.Version != 0 && payload.Version != dataVersion {\n\t\treturn fmt.Errorf(\"unsupported data version: %d\", payload.Version)\n\t}\n\tif payload.Proxies == nil {\n\t\treturn errors.New(\"proxies is required\")\n\t}\n\tif payload.Accounts == nil {\n\t\treturn errors.New(\"accounts is required\")\n\t}\n\treturn nil\n}\n\nfunc validateDataProxy(item DataProxy) error {\n\tif strings.TrimSpace(item.Protocol) == \"\" {\n\t\treturn errors.New(\"proxy protocol is required\")\n\t}\n\tif strings.TrimSpace(item.Host) == \"\" {\n\t\treturn errors.New(\"proxy host is required\")\n\t}\n\tif item.Port <= 0 || item.Port > 65535 {\n\t\treturn errors.New(\"proxy port is invalid\")\n\t}\n\tswitch item.Protocol {","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/Wei-Shaw/sub2api/blob/073e92d17178a1ccdb0a27017f572f10c9c7ab62/backend/internal/handler/admin/account_data.go#L628-L664","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\n{ \"type\": \"data\", \"version\": 1, \"accounts\": [ ... ] }\n\n// after\n{ \"type\": \"data\", \"version\": 1, \"proxies\": [], \"accounts\": [ ... ] }","handlingStrategy":"validation","validationCode":"function hasProxiesKey(payload: unknown): boolean {\n  return typeof payload === 'object' && payload !== null && 'proxies' in payload && Array.isArray((payload as any).proxies)\n}","typeGuard":"function isShapedDataPayload(p: unknown): p is { proxies: unknown[]; accounts?: unknown[] } {\n  return typeof p === 'object' && p !== null && Array.isArray((p as { proxies?: unknown }).proxies)\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["admin","import","json","validation","backend","data-format"],"backgroundTag":null,"analyzedSha":"073e92d17178a1ccdb0a27017f572f10c9c7ab62","analyzedAt":"2026-08-15T14:33:00.750Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}