{"record":{"id":"260e5060825c539c","repo":"remotion-dev/remotion","slug":"you-passed-in-a-function-to-the-volume-prop-but-it-260e50","errorCode":null,"errorMessage":"You passed in a function to the volume prop but it returned a non-finite number for frame ${frame}.","messagePattern":"You passed in a function to the volume prop but it returned a non-finite number for frame (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/volume-prop.ts","lineNumber":34,"sourceCode":"\tif (typeof volume === 'undefined') {\n\t\treturn Number(mediaVolume);\n\t}\n\n\tconst evaluated = volume(frame) * mediaVolume;\n\tif (typeof evaluated !== 'number') {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a a function to the volume prop but it did not return a number but a value of type ${typeof evaluated} for frame ${frame}`,\n\t\t);\n\t}\n\n\tif (Number.isNaN(evaluated)) {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a function to the volume prop but it returned NaN for frame ${frame}.`,\n\t\t);\n\t}\n\n\tif (!Number.isFinite(evaluated)) {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a function to the volume prop but it returned a non-finite number for frame ${frame}.`,\n\t\t);\n\t}\n\n\treturn Math.max(0, evaluated);\n};\n","sourceCodeStart":16,"sourceCodeEnd":41,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/volume-prop.ts#L16-L41","documentation":"TypeError thrown by `evaluateVolume` when the volume callback returns a non-finite number (Infinity or -Infinity). This passes the typeof number and NaN checks but fails `Number.isFinite`. Usually caused by division by zero producing Infinity, or unbounded arithmetic.","triggerScenarios":"A volume function that divides a non-zero numerator by zero (`1/0` -> Infinity), or multiplies toward Infinity. At least one frame yields an infinite value.","commonSituations":"Envelope/fade math dividing by an elapsed-time delta that is 0 mid-curve; exponential growth `Math.pow(base, f)` with base > 1 over many frames; accumulating sums that overflow.","solutions":["Clamp the result: `return Math.min(1, Math.max(0, value));`.","Guard zero divisors before dividing.","Return `Number.isFinite(v) ? v : 0` as a final safety net."],"exampleFix":"// before\n<Video src={s} volume={(f) => 1 / (100 - f)} /> // f=100 -> Infinity\n\n// after\n<Video src={s} volume={(f) => {\n  const v = 1 / (100 - f);\n  return Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : 0;\n}} />","handlingStrategy":"validation","validationCode":"const safeVolume = (v: (f: number) => number, frames: number[]) => {\n  for (const f of frames) {\n    if (!Number.isFinite(v(f))) throw new Error(`volume non-finite at frame ${f}`);\n  }\n};","typeGuard":"const returnsFinite = (v: (f: number) => number, f: number): boolean =>\n  Number.isFinite(v(f));","tryCatchPattern":null,"preventionTips":["Clamp volume output with Math.min/Math.max to [0,1].","Avoid unbounded exponential growth over many frames.","Use a final `Number.isFinite(v) ? v : 0` fallback."],"tags":["audio","volume","validation","infinity"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}