{"record":{"id":"7dc83b425d9208f6","repo":"AlexxIT/go2rtc","slug":"invalid-region-s","errorCode":null,"errorMessage":"invalid region: %s","messagePattern":"invalid region: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tuya/smart_api.go","lineNumber":272,"sourceCode":"\t{\"eu-central\", \"protect-eu.ismartlife.me\", \"Central Europe\", \"EU\"},\n\t{\"eu-east\", \"protect-we.ismartlife.me\", \"East Europe\", \"EU\"},\n\t{\"us-west\", \"protect-us.ismartlife.me\", \"West America\", \"AZ\"},\n\t{\"us-east\", \"protect-ue.ismartlife.me\", \"East America\", \"AZ\"},\n\t{\"china\", \"protect.ismartlife.me\", \"China\", \"AY\"},\n\t{\"india\", \"protect-in.ismartlife.me\", \"India\", \"IN\"},\n}\n\nfunc NewTuyaSmartApiClient(httpClient *http.Client, baseUrl, email, password, deviceId string) (*TuyaSmartApiClient, error) {\n\tvar region *Region\n\tfor _, r := range AvailableRegions {\n\t\tif r.Host == baseUrl {\n\t\t\tregion = &r\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif region == nil {\n\t\treturn nil, fmt.Errorf(\"invalid region: %s\", baseUrl)\n\t}\n\n\tif httpClient == nil {\n\t\thttpClient = CreateHTTPClientWithSession()\n\t}\n\n\tmqttClient := NewTuyaMqttClient(deviceId)\n\n\tclient := &TuyaSmartApiClient{\n\t\tTuyaClient: TuyaClient{\n\t\t\thttpClient: httpClient,\n\t\t\tmqtt:       mqttClient,\n\t\t\tdeviceId:   deviceId,\n\t\t\texpireTime: 0,\n\t\t\tbaseUrl:    baseUrl,\n\t\t},\n\t\temail:       email,\n\t\tpassword:    password,","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tuya/smart_api.go#L254-L290","documentation":"NewSmartApiClient (or the region resolution helper in smart_api.go) iterates the known region list looking for one matching the supplied baseUrl; if none matches it returns this error with the offending URL. It means the configured base URL is not one of the recognized Tuya data-center endpoints, so no client can be constructed.","triggerScenarios":"Passing a baseUrl to the Tuya smart API client factory that isn't in the library's region table — typos, custom/proxy URLs, missing scheme, or newly added Tuya regions not present in this library version.","commonSituations":"Copying a base URL from docs of a different SDK version, using an EU/India endpoint the library doesn't know, or trimming the scheme (https://) so the comparison fails.","solutions":["Use one of the library's exported/known region base URLs verbatim (e.g. openapi.tuya-XX.com)","Verify the exact spelling and scheme (https://) of baseUrl against the region list in smart_api.go","Upgrade the library if your Tuya data center is newer than the built-in region table","Add/patch the region entry locally if you must use a custom endpoint"],"exampleFix":"// before\nclient, err := tuya.NewSmartApiClient(\"openapi.tuya.example.com\", accessID, secret)\n// after\nclient, err := tuya.NewSmartApiClient(\"https://openapi.tuya-us.com\", accessID, secret)\nif err != nil { return fmt.Errorf(\"region config wrong: %w\", err) }","handlingStrategy":"validation","validationCode":"var knownRegions = []string{\"https://openapi.tuya-us.com\",\"https://openapi.tuya-eu.com\",\"https://openapi.tuya-china.com\",\"https://openapi.tuya-in.com\"}\nfunc validRegion(u string) bool { return slices.Contains(knownRegions, u) }","typeGuard":"func isKnownTuyaRegion(baseUrl string) bool {\n    return strings.HasPrefix(baseUrl, \"https://openapi.tuya-\")\n}","tryCatchPattern":"client, err := tuya.NewSmartApiClient(baseUrl, id, secret)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid region\") { return fmt.Errorf(\"bad region URL %q: %w\", baseUrl, err) }\n    return err\n}","preventionTips":["Store region URLs from the library's exported constants, not hand-typed strings","Keep scheme (https://) intact in config","Upgrade library when Tuya adds new data centers"],"tags":["go","tuya","region","configuration","invalid-url"],"backgroundTag":"invalid-config-value","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}