{"record":{"id":"db9daafbae549def","repo":"Wei-Shaw/sub2api","slug":"accounts-is-required","errorCode":null,"errorMessage":"accounts is required","messagePattern":"accounts is required","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"backend/internal/handler/admin/account_data.go","lineNumber":649,"sourceCode":"\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 {\n\tcase \"http\", \"https\", \"socks5\", \"socks5h\":\n\tdefault:\n\t\treturn fmt.Errorf(\"proxy protocol is invalid: %s\", item.Protocol)","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/Wei-Shaw/sub2api/blob/073e92d17178a1ccdb0a27017f572f10c9c7ab62/backend/internal/handler/admin/account_data.go#L631-L667","documentation":"Returned by validateDataHeader (backend/internal/handler/admin/account_data.go:649) when the top-level \"accounts\" key is missing from the data payload (payload.Accounts == nil). Like proxies, an explicitly empty array [] passes, but an absent key fails — the handler requires both containers to be present so accidental omission cannot silently import nothing.","triggerScenarios":"POSTing a payload with only \"proxies\" and no \"accounts\" key; a serializer configured to skip empty account lists; merging payload fragments and dropping the accounts branch.","commonSituations":"Proxy-only import attempted with a hand-trimmed JSON; Go/Python serializers with omitempty/skip-empty behavior; editing an export in a JSON editor and deleting the accounts key.","solutions":["Include \"accounts\": [] (or your accounts) in the payload's top level.","Fix the generating code to always emit the accounts array even when empty.","Validate presence of both keys before upload."],"exampleFix":"// before\n{ \"type\": \"data\", \"version\": 1, \"proxies\": [ ... ] }\n\n// after\n{ \"type\": \"data\", \"version\": 1, \"proxies\": [ ... ], \"accounts\": [] }","handlingStrategy":"validation","validationCode":"function hasAccountsKey(payload: unknown): boolean {\n  return typeof payload === 'object' && payload !== null && 'accounts' in payload && Array.isArray((payload as any).accounts)\n}","typeGuard":"function isShapedDataPayload(p: unknown): p is { proxies?: unknown[]; accounts: unknown[] } {\n  return typeof p === 'object' && p !== null && Array.isArray((p as { accounts?: unknown }).accounts)\n}","tryCatchPattern":null,"preventionTips":["Always include \"accounts\": [] in payloads even for proxy-only imports.","Ensure export code never skips empty arrays.","Check both required keys exist before POSTing."],"tags":["admin","import","json","validation","backend","data-format"],"backgroundTag":null,"analyzedSha":"073e92d17178a1ccdb0a27017f572f10c9c7ab62","analyzedAt":"2026-08-15T14:33:00.750Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}