{"record":{"id":"dbb61ae27d0f62ad","repo":"AlexxIT/go2rtc","slug":"failed-to-load-webrtc-config-w-dbb61a","errorCode":null,"errorMessage":"failed to load webrtc config: %w","messagePattern":"failed to load webrtc config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tuya/smart_api.go","lineNumber":305,"sourceCode":"\t\t\tbaseUrl:    baseUrl,\n\t\t},\n\t\temail:       email,\n\t\tpassword:    password,\n\t\tcountryCode: region.Continent,\n\t}\n\n\treturn client, nil\n}\n\n// WebRTC Flow\nfunc (c *TuyaSmartApiClient) Init() error {\n\tif err := c.initToken(); err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize token: %w\", err)\n\t}\n\n\twebrtcConfig, err := c.loadWebrtcConfig()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load webrtc config: %w\", err)\n\t}\n\n\thubConfig, err := c.loadHubConfig()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load hub config: %w\", err)\n\t}\n\n\tif err := c.mqtt.Start(hubConfig, webrtcConfig, c.skill.WebRTC); err != nil {\n\t\treturn fmt.Errorf(\"failed to start MQTT: %w\", err)\n\t}\n\n\tif c.skill.LowPower > 0 {\n\t\t_ = c.mqtt.WakeUp(c.localKey)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tuya/smart_api.go#L287-L323","documentation":"go2rtc's Tuya smart API client wraps any failure from loadWebrtcConfig() during initialization with this message. loadWebrtcConfig fetches the WebRTC signaling configuration (STUN/TURN/relay endpoints) from the Tuya cloud for the configured skill/region. Without it the client cannot start its MQTT-based signaling session, so Start() aborts.","triggerScenarios":"Calling TuyaSmartAPI Start() (or equivalent init path) when the HTTP request to Tuya's webrtc-config endpoint fails: bad accessId/accessKey, wrong region/country code, expired token despite initToken succeeding, network outage, or Tuya returning an error body.","commonSituations":"Incorrect region/endpoint configured for the Tuya IoT account; cloud API credentials revoked or quota exhausted; corporate firewall blocking Tuya API hosts; Tuya skill data missing WebRTC section for the device.","solutions":["Verify Tuya accessId/accessKey and countryCode/region match the account in the Tuya IoT platform","Log the wrapped inner error (%w) to see whether it is HTTP 4xx/5xx, DNS, or a parse failure","Confirm the device/skill actually supports WebRTC streaming in the Tuya cloud console","Check network connectivity and proxy/firewall rules to Tuya API endpoints","Retry after confirming the token is fresh; token expiry mid-flow can cascade into config fetch failure"],"exampleFix":"// before\nc := tuya.NewSmartAPI(accessID, accessKey, \"eu\") // wrong region for account\nerr := c.Start()\n// after\nc := tuya.NewSmartAPI(accessID, accessKey, \"us\") // region matching Tuya account\nif err := c.Start(); err != nil {\n    log.Errorf(\"tuya start: %v\", err) // inspect wrapped cause\n}","handlingStrategy":"try-catch","validationCode":"// Go: validate config before Start()\nif accessID == \"\" || accessKey == \"\" { return errors.New(\"tuya credentials missing\") }\nif !validRegion(countryCode) { return fmt.Errorf(\"unsupported region %q\", countryCode) }\nif err := pingTuyaAPI(region); err != nil { return fmt.Errorf(\"tuya API unreachable: %w\", err) }","typeGuard":"func hasWebrtcSkill(s *tuya.Skill) bool { return s != nil && s.WebRTC }","tryCatchPattern":"if err := c.Start(); err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) { /* retry with backoff */ }\n    else if strings.Contains(err.Error(), \"failed to load webrtc config\") { /* check credentials/region */ }\n    return err\n}","preventionTips":["Verify Tuya credentials and region in the IoT console before deploying","Pre-flight ping of Tuya API endpoints in health checks","Keep go2rtc updated for Tuya API response changes","Log wrapped inner errors, never swallow %w chains"],"tags":["tuya","webrtc","cloud-api","config"],"backgroundTag":"http-request-failed","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"}