🎥 Make videos programmatically with React
better error handling
Jonny Burger0b66c2b2050f
diff --git a/packages/lambda/src/cli/render.ts b/packages/lambda/src/cli/render.tsindex 30bd7842b0..97e7dd6ae4 100644--- a/packages/lambda/src/cli/render.ts+++ b/packages/lambda/src/cli/render.ts@@ -101,5 +101,10 @@ export const renderCommand = async (args: string[]) => {Log.info('Done! ' + res.bucketName);process.exit(0);}++ if (status.errors?.fatalErrorEncountered) {+ Log.error('Fatal error encountered. Exiting.');+ process.exit(1);+ }}};diff --git a/packages/lambda/src/functions/get-progress.ts b/packages/lambda/src/functions/get-progress.tsindex 9d66842ac7..6269ef668a 100644--- a/packages/lambda/src/functions/get-progress.ts+++ b/packages/lambda/src/functions/get-progress.ts@@ -20,6 +20,7 @@ import {streamToString} from '../shared/stream-to-string';import {getCurrentRegion} from './helpers/get-current-region';import {inspectErrors} from './helpers/inspect-errors';import {lambdaLs, lambdaReadFile} from './helpers/io';+import {isFatalError} from './helpers/is-fatal-error';type Options = {expectedBucketOwner: string;@@ -262,8 +263,11 @@ export const progressHandler = async (bucket: lambdaParams.bucketName,outputFile: outputFile(),timeToFinish,- errors,- errorExplanations,+ errors: {+ locations: errors,+ messages: errorExplanations,+ fatalErrorEncountered: errorExplanations.some(isFatalError),+ },currentTime: Date.now(),bucketSize,lambdasInvoked,diff --git a/packages/lambda/src/functions/helpers/inspect-errors.ts b/packages/lambda/src/functions/helpers/inspect-errors.tsindex 60eb20ff79..7934eb5738 100644--- a/packages/lambda/src/functions/helpers/inspect-errors.ts+++ b/packages/lambda/src/functions/helpers/inspect-errors.ts@@ -2,6 +2,8 @@ import {AwsRegion} from '../../pricing/aws-regions';import {streamToString} from '../../shared/stream-to-string';import {lambdaReadFile} from './io';+export const FAILED_TO_LAUNCH_TOKEN = 'Failed to launch browser.';+export const inspectErrors = async ({errs,bucket,@@ -32,7 +34,10 @@ export const inspectErrors = async ({}if (e.includes('FATAL:zygote_communication_linux.cc')) {- return 'Failed to launch browser. Will be retried - you can probably ignore this error.';+ return (+ FAILED_TO_LAUNCH_TOKEN ++ ' Will be retried - you can probably ignore this error.'+ );}// TODO: Make typesafe and handle errordiff --git a/packages/lambda/src/functions/helpers/is-fatal-error.ts b/packages/lambda/src/functions/helpers/is-fatal-error.tsnew file mode 100644index 0000000000..f3e2396cd5--- /dev/null+++ b/packages/lambda/src/functions/helpers/is-fatal-error.ts@@ -0,0 +1,9 @@+import {FAILED_TO_LAUNCH_TOKEN} from './inspect-errors';++export const isFatalError = (err: string) => {+ if (err.includes(FAILED_TO_LAUNCH_TOKEN)) {+ return false;+ }++ return true;+};diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.tsindex 4c9ce30af3..6217b4daf9 100644--- a/packages/renderer/src/get-compositions.ts+++ b/packages/renderer/src/get-compositions.ts@@ -69,7 +69,21 @@ export const getCompositions = async (serveUrl,});- await page.goto(`${serveUrl}/index.html?evaluation=true`);+ const urlToVisit = `${serveUrl}/index.html?evaluation=true`;+ const pageRes = await page.goto(urlToVisit);+ if (pageRes.status() !== 200) {+ throw new Error(+ `Error while getting compositions: Tried to go to ${urlToVisit} but the status code was not 200 as expected, but ${pageRes.status()}. Does the site you specified exist?`+ );+ }++ const isRemotionFn = await page.evaluate('window.getStaticCompositions');+ if (isRemotionFn === undefined) {+ throw new Error(+ `Error while getting compositions: Tried to go to ${urlToVisit} and verify that it is a Remotion project by checking if window.getStaticCompositions is defined. However, the function was undefined, which indicates that this is not a valid Remotion project. Please check the URL you passed.`+ );+ }+await page.waitForFunction('window.ready === true');const result = await page.evaluate('window.getStaticCompositions()');