{"record":{"id":"59d63ea8eea17383","repo":"AlexxIT/go2rtc","slug":"speaker-failed-with-rescode-d","errorCode":null,"errorMessage":"speaker failed with resCode: %d","messagePattern":"speaker failed with resCode: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tuya/mqtt.go","lineNumber":366,"sourceCode":"\tcandidateFrame.Candidate = strings.TrimPrefix(candidateFrame.Candidate, \"a=\")\n\tcandidateFrame.Candidate = strings.TrimSuffix(candidateFrame.Candidate, \"\\r\\n\")\n\n\tc.onCandidate(candidateFrame)\n}\n\nfunc (c *TuyaMqttClient) onMqttDisconnect() {\n\tc.closed = true\n\tc.onDisconnect()\n}\n\nfunc (c *TuyaMqttClient) onMqttSpeaker(msg *MqttMessage) {\n\tvar speakerResponse struct {\n\t\tResCode int `json:\"resCode\"`\n\t}\n\n\tif err := json.Unmarshal(msg.Data.Message, &speakerResponse); err == nil {\n\t\tif speakerResponse.ResCode != 0 {\n\t\t\tc.speakerWaiter.Done(fmt.Errorf(\"speaker failed with resCode: %d\", speakerResponse.ResCode))\n\t\t\treturn\n\t\t}\n\t}\n\n\tc.speakerWaiter.Done(nil)\n}\n\nfunc (c *TuyaMqttClient) onAnswer(answer AnswerFrame) {\n\tif c.handleAnswer != nil {\n\t\tc.handleAnswer(answer)\n\t}\n}\n\nfunc (c *TuyaMqttClient) onCandidate(candidate CandidateFrame) {\n\tif c.handleCandidate != nil {\n\t\tc.handleCandidate(candidate)\n\t}\n}","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tuya/mqtt.go#L348-L384","documentation":"onMqttSpeaker parses the incoming MQTT message for a resCode field; if resCode is non-zero it completes the speaker waiter with this error, failing the pending SendSpeaker call. It means the camera explicitly rejected the speaker command with the given response code. This error is only surfaced through SendSpeaker's 'speaker wait failed' wrapper.","triggerScenarios":"Any SendSpeaker call where the device's MQTT reply contains resCode != 0 (e.g. busy, decode failure, unsupported request). The JSON parse must succeed but the code is non-zero.","commonSituations":"Sending a second speaker command while one is active, sending during low-power state before the camera is fully awake, or a firmware that rejects certain resolutions/audio formats.","solutions":["Log/resCode-map the numeric code to a meaningful cause (busy, unsupported, busy-decoding)","Retry after the current operation completes or after waking the device","Adjust speaker request parameters (resolution, sample rate, HEVC flag) to values the device supports","Serialize speaker commands so overlapping calls don't get rejected"],"exampleFix":"// before\nerr := client.SendSpeaker(...)\nif err != nil { return err }\n// after\nerr := client.SendSpeaker(...)\nif err != nil {\n    var resCode int\n    if _, ferr := fmt.Sscanf(err.Error(), \"speaker failed with resCode: %d\", &resCode); ferr == nil {\n        return fmt.Errorf(\"device rejected speaker cmd (resCode=%d)\", resCode)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// validate speaker params against device capability table before sending\nif !supportedResolution(res) { return fmt.Errorf(\"unsupported resolution %s\", res) }","typeGuard":null,"tryCatchPattern":"err := client.SendSpeaker(...)\nif err != nil {\n    var rc int\n    if n, _ := fmt.Sscanf(err.Error(), \"speaker failed with resCode: %d\", &rc); n == 1 {\n        return mapResCode(rc)\n    }\n    return err\n}","preventionTips":["Map known resCodes to actionable messages in your integration","Avoid overlapping speaker operations","Confirm firmware supports the requested stream parameters"],"tags":["go","mqtt","device-response","rescode","speaker"],"backgroundTag":"api-error-response","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"}