{"record":{"id":"5d1cfef864233b2f","repo":"XTLS/Xray-core","slug":"failed-to-parse-socks-account","errorCode":null,"errorMessage":"failed to parse socks account","messagePattern":"failed to parse socks account","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/socks.go","lineNumber":127,"sourceCode":"\t\t\tPort:    uint32(serverConfig.Port),\n\t\t}\n\t\tfor _, rawUser := range serverConfig.Users {\n\t\t\tuser := new(protocol.User)\n\t\t\tif v.Address != nil {\n\t\t\t\tuser.Level = v.Level\n\t\t\t\tuser.Email = v.Email\n\t\t\t} else {\n\t\t\t\tif err := json.Unmarshal(rawUser, user); err != nil {\n\t\t\t\t\treturn nil, errors.New(\"failed to parse Socks user\").Base(err).AtError()\n\t\t\t\t}\n\t\t\t}\n\t\t\taccount := new(SocksAccount)\n\t\t\tif v.Address != nil {\n\t\t\t\taccount.Username = v.Username\n\t\t\t\taccount.Password = v.Password\n\t\t\t} else {\n\t\t\t\tif err := json.Unmarshal(rawUser, account); err != nil {\n\t\t\t\t\treturn nil, errors.New(\"failed to parse socks account\").Base(err).AtError()\n\t\t\t\t}\n\t\t\t}\n\t\t\tuser.Account = serial.ToTypedMessage(account.Build())\n\t\t\tserver.User = user\n\t\t\tbreak\n\t\t}\n\t\tconfig.Server = server\n\t\tbreak\n\t}\n\treturn config, nil\n}\n","sourceCodeStart":109,"sourceCodeEnd":139,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/socks.go#L109-L139","documentation":"After decoding the user envelope, Xray unmarshals the same raw JSON object into SocksAccount (infra/conf/socks.go:126-127) to read username/password. If the object's \"user\"/\"pass\" fields exist but are not strings (or the entry is not an object at all), config load fails with \"failed to parse socks account\".","triggerScenarios":"A servers[].users[i] object where \"user\" or \"pass\" is a number, boolean, object, or null-adjacent mismatch, e.g. {\"user\":12345,\"pass\":\"x\"}. Field names must be exactly \"user\" and \"pass\" (not \"username\"/\"password\") — wrong names simply leave credentials empty but do not error; wrong types do.","commonSituations":"Using \"username\"/\"password\" keys from another client's docs and then also mis-typing values; auto-generated configs that insert numeric usernames without quoting; mixing inbound account schema ({\"user\",\"pass\"} per inbound) into outbound users with numeric values.","solutions":["Quote both credentials: {\"user\":\"12345\",\"pass\":\"secret\"}","Use the exact keys \"user\" and \"pass\"","Or switch to the legacy flat settings form {\"address\",...,\"user\":\"...\",\"pass\":\"...\"} which bypasses raw unmarshaling"],"exampleFix":"// before\n\"users\": [ { \"user\": 12345, \"pass\": true } ]\n// after\n\"users\": [ { \"user\": \"12345\", \"pass\": \"true\" } ]","handlingStrategy":"validation","validationCode":"for (const u of server.users ?? []) {\n  if ('user' in u && typeof u.user !== 'string') throw new Error('socks \"user\" must be a string');\n  if ('pass' in u && typeof u.pass !== 'string') throw new Error('socks \"pass\" must be a string');\n}","typeGuard":"const isSocksAccount = (u: unknown): u is {user:string; pass:string} =>\n  typeof u === 'object' && u !== null &&\n  (u as any).user === undefined || typeof (u as any).user === 'string' &&\n  (u as any).pass === undefined || typeof (u as any).pass === 'string';","tryCatchPattern":"catch (e) { if (e.message.includes('failed to parse socks account')) { /* check user/pass types in users[i] */ } }","preventionTips":["Use keys \"user\" and \"pass\" with string values only","Prefer the flat settings form for single-credential outbounds"],"tags":["xray","go","json","socks","config"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}