{"record":{"id":"9a874be7d90812d1","repo":"XTLS/Xray-core","slug":"invalid-trojan-port","errorCode":null,"errorMessage":"Invalid Trojan port.","messagePattern":"Invalid Trojan port\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/trojan.go","lineNumber":68,"sourceCode":"\t\t\t\tLevel:    c.Level,\n\t\t\t\tEmail:    c.Email,\n\t\t\t\tPassword: c.Password,\n\t\t\t\tFlow:     c.Flow,\n\t\t\t},\n\t\t}\n\t}\n\tif len(c.Servers) != 1 {\n\t\treturn nil, errors.New(`Trojan settings: \"servers\" should have one and only one member. Multiple endpoints in \"servers\" should use multiple Trojan outbounds and routing balancer instead`)\n\t}\n\n\tconfig := &trojan.ClientConfig{}\n\n\tfor _, rec := range c.Servers {\n\t\tif rec.Address == nil {\n\t\t\treturn nil, errors.New(\"Trojan server address is not set.\")\n\t\t}\n\t\tif rec.Port == 0 {\n\t\t\treturn nil, errors.New(\"Invalid Trojan port.\")\n\t\t}\n\t\tif rec.Password == \"\" {\n\t\t\treturn nil, errors.New(\"Trojan password is not specified.\")\n\t\t}\n\t\tif rec.Flow != \"\" {\n\t\t\treturn nil, errors.PrintRemovedFeatureError(`Flow for Trojan`, ``)\n\t\t}\n\n\t\tconfig.Server = &protocol.ServerEndpoint{\n\t\t\tAddress: rec.Address.Build(),\n\t\t\tPort:    uint32(rec.Port),\n\t\t\tUser: &protocol.User{\n\t\t\t\tLevel: uint32(rec.Level),\n\t\t\t\tEmail: rec.Email,\n\t\t\t\tAccount: serial.ToTypedMessage(&trojan.Account{\n\t\t\t\t\tPassword: rec.Password,\n\t\t\t\t}),\n\t\t\t},","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/trojan.go#L50-L86","documentation":"Thrown when the Trojan server entry has a port of 0 — either the 'port' key is missing/null (defaults to 0) or is explicitly 0. Port 0 is treated as invalid for a Trojan endpoint.","triggerScenarios":"Omitting \"port\" from the servers object, setting \"port\": 0, or a JSON string port \"\"443\"\" that fails to decode into the numeric field.","commonSituations":"Copy-paste from a share link where the port got lost, or quoting the port (\"port\": \"443\") so it never lands in the numeric Port field.","solutions":["Set a valid TCP port 1-65535, e.g. \"port\": 443","Make sure the value is a JSON number, not a string","Check the server actually listens on that port (commonly 443)"],"exampleFix":"// before\n{ \"address\": \"trojan.example.com\", \"port\": 0, \"password\": \"secret\" }\n// after\n{ \"address\": \"trojan.example.com\", \"port\": 443, \"password\": \"secret\" }","handlingStrategy":"validation","validationCode":"port := gjson.Get(serverRaw, \"port\").Uint()\nif port == 0 || port > 65535 {\n    return fmt.Errorf(\"trojan server port must be 1-65535, got %d\", port)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always emit port as a JSON number","Validate port range in tooling before writing config"],"tags":["config","trojan","port","validation"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}