{"record":{"id":"f1ef177e65f83c37","repo":"heygen-com/hyperframes","slug":"err-instanceof-error-err-message-string-err","errorCode":null,"errorMessage":"${err instanceof Error ? err.message : String(err)}${detail}","messagePattern":"\\$\\{err instanceof Error \\? err\\.message : String\\(err\\)\\}\\$\\{detail\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/beats/headlessAnalyzer.ts","lineNumber":125,"sourceCode":"}\n\n// Load the analyzer bundle into the page, run analysis, and surface in-page\n// errors (decode/codec failures, missing global) instead of an opaque rejection.\nasync function detectOnPage(page: Page, bundle: string, b64: string): Promise<HeadlessBeatResult> {\n  const pageErrors: string[] = [];\n  page.on(\"pageerror\", (e) => {\n    pageErrors.push((e as Error).message);\n  });\n  page.on(\"console\", (m) => {\n    if (m.type() === \"error\") pageErrors.push(m.text());\n  });\n  await page.setContent(\"<!doctype html><html><body></body></html>\");\n  await page.addScriptTag({ content: bundle });\n  try {\n    return (await page.evaluate(inPageAnalyze, b64)) as HeadlessBeatResult;\n  } catch (err) {\n    const detail = pageErrors.length ? ` (${pageErrors.join(\"; \")})` : \"\";\n    throw new Error(`${err instanceof Error ? err.message : String(err)}${detail}`);\n  }\n}\n\n/** Decode + analyze the given audio bytes in headless Chrome. */\nexport async function analyzeBeatsHeadless(audioBytes: Buffer): Promise<HeadlessBeatResult> {\n  if (audioBytes.length > MAX_AUDIO_BYTES) {\n    const mb = Math.round(audioBytes.length / 1e6);\n    throw new Error(\n      `Audio file too large for headless analysis (${mb}MB > ${MAX_AUDIO_BYTES / 1e6}MB).`,\n    );\n  }\n  const bundle = await buildAnalyzerBundle();\n  const { ensureBrowser } = await import(\"../browser/manager.js\");\n  const puppeteer = await import(\"puppeteer-core\");\n  const browser = await ensureBrowser();\n  const chrome: Browser = await puppeteer.default.launch({\n    headless: true,\n    executablePath: browser.executablePath,","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/cli/src/beats/headlessAnalyzer.ts#L107-L143","documentation":"Thrown by detectOnPage() as a catch-all wrapper around any failure from page.evaluate(inPageAnalyze). It takes the underlying error's message (or String(err)) and appends collected page-error/console-error strings in parentheses so the cause of an opaque CDP rejection is visible. Common underlying causes: AudioContext.decodeAudioData rejected (unsupported codec, corrupt audio), __hfAnalyze threw, or the page crashed.","triggerScenarios":"analyzeBeatsHeadless() calls detectOnPage(page, bundle, b64); page.evaluate throws because the audio bytes could not be decoded by the Web Audio decoder (e.g. a .wma or obscure codec), or inPageAnalyze threw for any reason.","commonSituations":"Input audio is in a format Chrome's Web Audio cannot decode (e.g. WMA, ATRAC, some FLAC variants on older Chrome); the audio buffer is truncated/corrupt; a transient page-level JS error occurred during analysis.","solutions":["Read the parenthesized detail in the message — it carries the in-page error (e.g. 'Failed to decode audio data').","Convert the audio to a broadly supported format: `ffmpeg -i in.wma -c:a libmp3lame -q:a 2 out.mp3` or to WAV.","Verify the file is a valid audio container: `ffprobe in.mp3`."],"exampleFix":"# before — Chrome cannot decode WMA\n$ bunx hyperframes beats clip.wma\n# convert to mp3\n$ ffmpeg -i clip.wma -c:a libmp3lame -q:a 2 clip.mp3\n$ bunx hyperframes beats clip.mp3","handlingStrategy":"try-catch","validationCode":"import { execFileSync } from 'node:child_process';\nfunction audioDecodes(p: string): boolean {\n  try {\n    execFileSync('ffprobe', ['-v', 'error', '-select_streams', 'a', '-show_entries', 'stream=codec_name', '-of', 'csv=p=0', p], { encoding: 'utf-8' });\n    return true;\n  } catch { return false; }\n}\nif (!audioDecodes(inputPath)) throw new Error('Audio file is not decodable; convert to mp3/wav.');","typeGuard":null,"tryCatchPattern":"try {\n  await analyzeBeatsHeadless(buf);\n} catch (err) {\n  const msg = (err as Error).message;\n  if (/decode|audio/i.test(msg)) {\n    // convert to mp3 and retry\n  }\n  throw err;\n}","preventionTips":["Feed mp3, wav, m4a, or ogg — formats Chrome's Web Audio decodes reliably.","Validate the audio with ffprobe before analysis.","Read the parenthesized page-error detail in the wrapped message to find the decode cause."],"tags":["beats","audio-decode","headless-chrome","wrapping-error","runtime"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}