{"record":{"id":"f1e965d9beef8b26","repo":"Wei-Shaw/sub2api","slug":"proxy-host-is-required","errorCode":null,"errorMessage":"proxy host is required","messagePattern":"proxy host is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/internal/handler/admin/account_data.go","lineNumber":659,"sourceCode":"\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)\n\t}\n\tif item.Status != \"\" {\n\t\tnormalizedStatus := normalizeProxyStatus(item.Status)\n\t\tif normalizedStatus != service.StatusActive && normalizedStatus != \"inactive\" {\n\t\t\treturn fmt.Errorf(\"proxy status is invalid: %s\", item.Status)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/Wei-Shaw/sub2api/blob/073e92d17178a1ccdb0a27017f572f10c9c7ab62/backend/internal/handler/admin/account_data.go#L641-L677","documentation":"Returned by validateDataProxy (backend/internal/handler/admin/account_data.go:659) when a proxy entry's host is empty after TrimSpace — the protocol was present but the hostname/IP is missing. Host is required even for schemes where it might seem optional; there is no default.","triggerScenarios":"A proxies[] entry with protocol and port but host absent, blank, or whitespace-only; URL parsing that put everything in a single field ('host': \"socks5://127.0.0.1:1080\" with port 0 does not hit this but a plain empty host does).","commonSituations":"Form where host field was skipped; data migrated from a format with a combined URL string; env-var-driven configs pasted with the host line missing.","solutions":["Set host to the proxy's hostname or IP on the entry.","If your source stores a full URL, split it into protocol/host/port fields before import.","Ensure no entry was truncated when copying JSON."],"exampleFix":"// before\n{ \"protocol\": \"http\", \"port\": 8080 }\n\n// after\n{ \"protocol\": \"http\", \"host\": \"proxy.example.com\", \"port\": 8080 }","handlingStrategy":"validation","validationCode":"function hasProxyHost(entry: Record<string, unknown>): boolean {\n  return typeof entry.host === 'string' && entry.host.trim() !== ''\n}","typeGuard":"function isNonEmptyHost(h: unknown): h is string {\n  return typeof h === 'string' && h.trim().length > 0 && /^[^:]+(:\\d+)?$/.test(h.trim()) === false || (typeof h === 'string' && h.trim() !== '' && !h.includes(':'))\n}","tryCatchPattern":null,"preventionTips":["Split combined 'scheme://host:port' URL strings into discrete fields before import.","Require the host field in the UI form.","Verify JSON entries were not truncated during copy-paste."],"tags":["admin","import","proxy","validation","backend"],"backgroundTag":null,"analyzedSha":"073e92d17178a1ccdb0a27017f572f10c9c7ab62","analyzedAt":"2026-08-15T14:33:00.750Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}