🎥 Make videos programmatically with React
error overlay 4.0
Jonny Burger98e60136c535
diff --git a/packages/bundler/src/error-overlay/entry-basic.ts b/packages/bundler/src/error-overlay/entry-basic.tsindex a623cf1021..86da1f005b 100644--- a/packages/bundler/src/error-overlay/entry-basic.ts+++ b/packages/bundler/src/error-overlay/entry-basic.ts@@ -6,6 +6,8 @@ import {import {mountRemotionOverlay} from './remotion-overlay';import {setErrorsRef} from './remotion-overlay/Overlay';+console.log(__filename);+startReportingRuntimeErrors({onError() {if (module.hot) {@@ -23,5 +25,7 @@ startReportingRuntimeErrors({});}},+ // TODO: Adapt to dynamic base in Lambda+ filename: '/bundle.js',});mountRemotionOverlay();diff --git a/packages/bundler/src/error-overlay/react-overlay/effects/map-error-to-react-stack.ts b/packages/bundler/src/error-overlay/react-overlay/effects/map-error-to-react-stack.tsindex a34894490b..2eb0eda423 100644--- a/packages/bundler/src/error-overlay/react-overlay/effects/map-error-to-react-stack.ts+++ b/packages/bundler/src/error-overlay/react-overlay/effects/map-error-to-react-stack.ts@@ -12,7 +12,10 @@ export const getLocationFromBuildError = (err: Error): ErrorLocation | null => {return null;}- if (!err.stack.startsWith('Error: Module build failed')) {+ if (+ !err.stack.startsWith('Error: Module build failed') &&+ !err.stack.startsWith('Error: Cannot find module')+ ) {return null;}@@ -25,21 +28,33 @@ export const getLocationFromBuildError = (err: Error): ErrorLocation | null => {return null;}- if (s.match(/^\s+at/g)) {- return null;+ const matchWebpackOrEsbuild = s.match(/(.*):([0-9]+):([0-9]+): (.*)/);++ if (matchWebpackOrEsbuild) {+ return {+ fileName: matchWebpackOrEsbuild[1],+ lineNumber: Number(matchWebpackOrEsbuild[2]),+ columnNumber: Number(matchWebpackOrEsbuild[3]),+ message: matchWebpackOrEsbuild[4],+ };}- const matchWebpackOrEsbuild = s.match(/(.*):([0-9]+):([0-9]+): (.*)/);+ const matchMissingModule = s.match(/\s+at(.*)\s\((.*)\)/);+ if (!matchMissingModule) {+ return null;+ }- if (!matchWebpackOrEsbuild) {+ if (s.includes('webpackMissingModule')) {return null;}+ const [, filename] = matchMissingModule;+return {- fileName: matchWebpackOrEsbuild[1],- lineNumber: Number(matchWebpackOrEsbuild[2]),- columnNumber: Number(matchWebpackOrEsbuild[3]),- message: matchWebpackOrEsbuild[4],+ columnNumber: 0,+ lineNumber: 1,+ message: split[0],+ fileName: filename.trim(),};}).filter(Internals.truthy)[0] ?? nulldiff --git a/packages/bundler/src/error-overlay/react-overlay/index.ts b/packages/bundler/src/error-overlay/react-overlay/index.tsindex 82adf851b5..0682dff6f5 100644--- a/packages/bundler/src/error-overlay/react-overlay/index.ts+++ b/packages/bundler/src/error-overlay/react-overlay/index.ts@@ -4,7 +4,7 @@ import {ErrorRecord, listenToRuntimeErrors} from './listen-to-runtime-errors';let stopListeningToRuntimeErrors: null | (() => void) = null;type RuntimeReportingOptions = {onError: () => void;- filename?: string;+ filename: string;};let currentRuntimeErrorRecords: ErrorRecord[] = [];@@ -25,8 +25,9 @@ export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {const handleRuntimeError =(opts: RuntimeReportingOptions) => (errorRecord: ErrorRecord) => {try {+ console.log({errorRecord});if (typeof opts.onError === 'function') {- opts.onError.call(null);+ opts.onError();}} finally {if (@@ -54,6 +55,6 @@ export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {stopListeningToRuntimeErrors = listenToRuntimeErrors(handleRuntimeError(options),- options.filename as string+ options.filename);}diff --git a/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts b/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.tsindex 209e61a768..6f21baee98 100644--- a/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts+++ b/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts@@ -79,7 +79,15 @@ export function listenToRuntimeErrors(const crashWithFramesRunTime = crashWithFrames(crash);registerError(window, (error) => {- return crashWithFramesRunTime(error, false);+ return crashWithFramesRunTime(+ {+ message: error.message,+ stack: error.stack,+ __unmap_source: filename,+ name: error.name,+ },+ false+ );});registerPromise(window, (error) => {return crashWithFramesRunTime(error, true);@@ -90,6 +98,7 @@ export function listenToRuntimeErrors(if (d.type === 'webpack-error') {const {message, frames} = d;const data = massageWarning(message, frames);+crashWithFramesRunTime({message: data.message,diff --git a/packages/bundler/src/error-overlay/react-overlay/utils/get-stack-frames.ts b/packages/bundler/src/error-overlay/react-overlay/utils/get-stack-frames.tsindex d1ab20ef95..3c25dc7b3a 100644--- a/packages/bundler/src/error-overlay/react-overlay/utils/get-stack-frames.ts+++ b/packages/bundler/src/error-overlay/react-overlay/utils/get-stack-frames.ts@@ -27,6 +27,7 @@ const getEnhancedFrames = async (frames: StackFrame[];type: 'exception' | 'syntax';}> => {+ console.log({error});if (error.__unmap_source) {return {frames: await unmap(error.__unmap_source, parsedFrames, contextSize),diff --git a/packages/bundler/src/error-overlay/react-overlay/utils/unmapper.ts b/packages/bundler/src/error-overlay/react-overlay/utils/unmapper.tsindex 772fd28687..552b396e59 100644--- a/packages/bundler/src/error-overlay/react-overlay/utils/unmapper.ts+++ b/packages/bundler/src/error-overlay/react-overlay/utils/unmapper.ts@@ -49,7 +49,14 @@ async function unmap(}const map = await getSourceMap(fileUri, fileContents as string);+ console.log({map, fileContents, frames});+return frames.map((frame) => {+ const pos = map.getOriginalPosition(+ frame.lineNumber as number,+ frame.columnNumber as number+ );+ console.log(map.getSource(pos.source).split('\n')[pos.line - 1]);const {functionName, lineNumber, columnNumber, _originalLineNumber} = frame;if (_originalLineNumber != null) {return frame;diff --git a/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx b/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsxindex 2c82cc3b95..b83a39ca6c 100644--- a/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx+++ b/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx@@ -48,7 +48,9 @@ export const StackElement: React.FC<{<div><div style={header}><div style={left}>- <div style={fnName}>{s.functionName ?? defaultFunctionName}</div>+ <div style={fnName}>+ {s.functionName ?? s._originalFunctionName ?? defaultFunctionName}+ </div>{s._originalFileName ? (<div style={location}>{formatLocation(s._originalFileName as string)}:diff --git a/packages/bundler/src/test/parse-module-not-found.test.ts b/packages/bundler/src/test/parse-module-not-found.test.tsnew file mode 100644index 0000000000..991790266c--- /dev/null+++ b/packages/bundler/src/test/parse-module-not-found.test.ts@@ -0,0 +1,20 @@+import {getLocationFromBuildError} from '../error-overlay/react-overlay/effects/map-error-to-react-stack';++const message = "Cannot find module 'does not exist'";+const stack =+ "Error: Cannot find module 'does not exist'\n at webpackMissingModule (http://localhost:3000/bundle.js:1669:50)\n at ./src/Video.tsx (http://localhost:3000/bundle.js:1669:139)\n at Module.options.factory (http://localhost:3000/bundle.js:142235:31)\n at __webpack_require__ (http://localhost:3000/bundle.js:141612:33)\n at fn (http://localhost:3000/bundle.js:141890:21)\n at ./src/index.tsx (http://localhost:3000/bundle.js:2114:64)\n at Module.options.factory (http://localhost:3000/bundle.js:142235:31)\n at __webpack_require__ (http://localhost:3000/bundle.js:141612:33)\n at http://localhost:3000/bundle.js:142842:11\n at http://localhost:3000/bundle.js:142846:12";++test('Parse error stack', () => {+ expect(+ getLocationFromBuildError({+ stack,+ message,+ name: 'Error',+ })+ ).toEqual({+ fileName: './src/Video.tsx',+ lineNumber: 1,+ columnNumber: 0,+ message: "Error: Cannot find module 'does not exist'",+ });+});diff --git a/packages/example/src/VideoTesting/index.tsx b/packages/example/src/VideoTesting/index.tsxindex 0ad749d0a6..8cca16cec4 100644--- a/packages/example/src/VideoTesting/index.tsx+++ b/packages/example/src/VideoTesting/index.tsx@@ -8,7 +8,7 @@ export const VideoTesting: React.FC<{const videoWebm = staticFile('./framer.webm');return (<div>- <Sequence from={0} durationInFrames={durationInFrames}>+ <Sequence from={0} durationInFrames={-10000}><Video src={codec === 'mp4' ? videoMp4 : videoWebm} /></Sequence></div>