{"record":{"id":"107ab743d834e6b0","repo":"iflytek/astron-agent","slug":"msg-dynamic-logged-as-msg-and-shown-via-message-info","errorCode":null,"errorMessage":"msg (dynamic; logged as '无法录音:'+msg and shown via message.info)","messagePattern":"msg \\(dynamic; logged as '无法录音:'\\+msg and shown via message\\.info\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"console/frontend/src/utils/record/media.js","lineNumber":270,"sourceCode":"\n        _this.rec.open(\n          () => {\n            //打开麦克风授权获得相关资源\n            clearTimeout(t);\n            _this.rec.start(); //开始录音\n\n            _this.RealTimeSendTryReset(); //重置环境，开始录音时必须调用一次\n            resolve('success');\n          },\n          function (msg, isUserNotAllow) {\n            clearTimeout(t);\n            message.info(msg);\n            console.error(\n              (isUserNotAllow ? 'UserNotAllow，' : '') + '无法录音:' + msg,\n              1\n            );\n            reject(msg);\n            throw new Error(msg);\n          }\n        );\n      });\n    },\n\n    sendData: function (audioData) {\n      // console.log(\"audioData=>\", audioData)\n      this.ws.send(audioData);\n      this.status = 1;\n    },\n  };\n}\nexport default Media;\n","sourceCodeStart":252,"sourceCodeEnd":284,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/frontend/src/utils/record/media.js#L252-L284","documentation":"In the recorder wrapper's open() promise flow, when opening the microphone fails the code shows message.info(msg), logs '无法录音:'+msg, rejects the promise, and then throws new Error(msg). The message text is dynamic — it comes from the underlying recorder-core failure (permission denied, no device, environment check, etc.).","triggerScenarios":"Calling the wrapper's open/start when getUserMedia fails: user denied permission, no microphone available, page not in a secure context (non-HTTPS), recorder already open/closed, or an unsupported browser environment detected by Recorder.envCheck.","commonSituations":"Users blocking mic permission in Chrome; running the console on http:// during development so getUserMedia is undefined; kiosk/VM machines without an audio input device; iOS Safari restrictions.","solutions":["Read the rejected/caught msg and route it: if isUserNotAllow, instruct the user to re-enable microphone permission in browser settings","Serve the app over HTTPS (or localhost) so getUserMedia is available","Check navigator.mediaDevices and Recorder.Support() before attempting to open","Catch the error from the promise and stop the recording UI gracefully instead of letting the throw propagate"],"exampleFix":"// before\ntry { await media.open(); } catch (e) { throw e; }\n// after\ntry {\n  await media.open();\n} catch (msg) {\n  if (/UserNotAllow|NotAllowedError/.test(String(msg))) {\n    message.warning('请在浏览器设置中允许麦克风权限');\n  } else {\n    message.error('无法录音: ' + msg);\n  }\n}","handlingStrategy":"try-catch","validationCode":"if (!navigator.mediaDevices || !Recorder.Support()) {\n  message.error('当前环境不支持录音，请使用 HTTPS 的现代浏览器');\n  return;\n}","typeGuard":"function canRecord() {\n  return !!(navigator.mediaDevices && typeof navigator.mediaDevices.getUserMedia === 'function');\n}","tryCatchPattern":"try {\n  await media.open();\n} catch (msg) {\n  message.error((String(msg).includes('UserNotAllow') ? '请允许麦克风权限' : '无法录音: ') + msg);\n}","preventionTips":["Serve over HTTPS or localhost","Request mic permission early with a clear UX prompt","Check Recorder.Support() before mounting recording UI"],"tags":["audio","microphone","permissions","browser"],"backgroundTag":"permission-denied","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}