{"record":{"id":"a3a7bf2db370bbab","repo":"Wei-Shaw/sub2api","slug":"proxy-port-is-invalid","errorCode":null,"errorMessage":"proxy port is invalid","messagePattern":"proxy port is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/internal/handler/admin/account_data.go","lineNumber":662,"sourceCode":"\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\nfunc validateDataAccount(item DataAccount) error {\n\tif strings.TrimSpace(item.Name) == \"\" {\n\t\treturn errors.New(\"account name is required\")","sourceCodeStart":644,"sourceCodeEnd":680,"githubUrl":"https://github.com/Wei-Shaw/sub2api/blob/073e92d17178a1ccdb0a27017f572f10c9c7ab62/backend/internal/handler/admin/account_data.go#L644-L680","documentation":"Returned by validateDataProxy (backend/internal/handler/admin/account_data.go:662) when a proxy entry's port is outside 1-65535 (port <= 0 or > 65535). It fires after protocol and host checks, before the protocol whitelist and status validation.","triggerScenarios":"port omitted (defaults to 0 in Go), set to a negative number, or above 65535 (e.g. a 32-bit overflow or a pasted value like '127.0.0.1:1080' jammed into the port field).","commonSituations":"Omitting port because the scheme implies one (http=80); spreadsheets reformatting ports as numbers with thousands separators; copy-paste of full URLs into the port field.","solutions":["Set port to an integer between 1 and 65535 on the entry.","If port was omitted intentionally for a default, write the default explicitly (e.g. 80 for http, 443 for https).","Split combined 'host:port' strings before building the payload."],"exampleFix":"// before\n{ \"protocol\": \"https\", \"host\": \"proxy.example.com\" } // port 0\n\n// after\n{ \"protocol\": \"https\", \"host\": \"proxy.example.com\", \"port\": 443 }","handlingStrategy":"validation","validationCode":"function isValidProxyPort(port: unknown): boolean {\n  return typeof port === 'number' && Number.isInteger(port) && port >= 1 && port <= 65535\n}","typeGuard":"function isValidPort(p: unknown): p is number {\n  return typeof p === 'number' && Number.isInteger(p) && p >= 1 && p <= 65535\n}","tryCatchPattern":null,"preventionTips":["Write the scheme's default port explicitly (80/443/1080) instead of omitting it.","Use integer-only number inputs with min=1 max=65535 in forms.","Never paste 'host:port' into the port field; split first."],"tags":["admin","import","proxy","validation","backend","port"],"backgroundTag":null,"analyzedSha":"073e92d17178a1ccdb0a27017f572f10c9c7ab62","analyzedAt":"2026-08-15T14:33:00.750Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}