{"record":{"id":"07036c72767059c2","repo":"AlexxIT/go2rtc","slug":"wrong-login-step","errorCode":null,"errorMessage":"wrong login step","messagePattern":"wrong login step","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/xiaomi/cloud.go","lineNumber":132,"sourceCode":"\n\tif v2.NotificationURL != \"\" {\n\t\treturn c.authStart(v2.NotificationURL)\n\t}\n\n\tif v2.Location == \"\" {\n\t\treturn fmt.Errorf(\"xiaomi: %s\", body)\n\t}\n\n\tc.auth = nil\n\tc.ssecurity = v2.Ssecurity\n\tc.passToken = v2.PassToken\n\n\treturn c.finishAuth(v2.Location)\n}\n\nfunc (c *Cloud) LoginWithCaptcha(captcha string) error {\n\tif c.auth == nil || c.auth[\"ick\"] == \"\" {\n\t\tpanic(\"wrong login step\")\n\t}\n\n\tc.auth[\"captcha_code\"] = captcha\n\n\t// check if captcha after verify\n\tif c.auth[\"flag\"] != \"\" {\n\t\treturn c.sendTicket()\n\t}\n\n\treturn c.Login(c.auth[\"username\"], c.auth[\"password\"])\n}\n\nfunc (c *Cloud) LoginWithVerify(ticket string) error {\n\tif c.auth == nil || c.auth[\"flag\"] == \"\" {\n\t\tpanic(\"wrong login step\")\n\t}\n\n\treq := Request{","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/xiaomi/cloud.go#L114-L150","documentation":"Xiaomi cloud login is a multi-step state machine. LoginWithCaptcha requires that an earlier step (LoginStep) has already stored the \"ick\" cookie in c.auth. If auth state is missing or \"ick\" is empty, the method panics because a captcha cannot be submitted without the prior response context.","triggerScenarios":"Calling Cloud.LoginWithCaptcha before calling the initial LoginStep, calling it twice, or calling it on a fresh Cloud instance.","commonSituations":"Developers scripting the Xiaomi Mi Home cloud login out of order (captcha flow requires: login step -> captcha -> verify); retrying captcha submission after process restart loses auth state.","solutions":["Call the initial login step (c.LoginStep(...)) first so c.auth gets populated with the \"ick\" value, then call LoginWithCaptcha","Reuse the same Cloud instance across the whole login flow instead of creating a new one per step","Replace the panic with a returned error in a wrapper if you want graceful handling in your own code"],"exampleFix":"// before\ncloud := &xiaomi.Cloud{}\ncloud.LoginWithCaptcha(\"1234\")\n// after\ncloud := &xiaomi.Cloud{}\nif err := cloud.LoginStep(user, pass); err != nil { return err }\nif err := cloud.LoginWithCaptcha(\"1234\"); err != nil { return err }","handlingStrategy":"validation","validationCode":"if cloud.Auth == nil || cloud.Auth[\"ick\"] == \"\" {\n    return errors.New(\"must call login step before LoginWithCaptcha\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run the login steps in order on the same Cloud instance","Check auth state before each step","Don't recreate the Cloud object between steps"],"tags":["xiaomi","auth","login","panic","state-machine"],"backgroundTag":"invalid-state-transition","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}