Skip to content

πŸŽ₯ Make videos programmatically with React

lambda + cli

Jonny Burger1265ee104082
diff --git a/packages/cli/src/handle-common-errors.ts b/packages/cli/src/handle-common-errors.ts
deleted file mode 100644
index 24304077ca..0000000000
--- a/packages/cli/src/handle-common-errors.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-import type {LogLevel} from '@remotion/renderer';
-import {chalk} from './chalk';
-import {Log} from './log';
-import {printError} from './print-error';
-import {truthy} from './truthy';
-
-export const handleCommonError = async (err: Error, logLevel: LogLevel) => {
- await printError(err, logLevel);
- if (err.message.includes('Could not play video with')) {
- Log.info();
- Log.info(
- 'πŸ’‘ Get help for this issue at https://remotion.dev/docs/media-playback-error',
- );
- }
-
- if (
- err.message.includes('A delayRender()') &&
- err.message.includes('was called but not cleared after')
- ) {
- Log.info();
- Log.info('πŸ’‘ Get help for this issue at https://remotion.dev/docs/timeout');
- }
-
- if (err.message.includes('Target closed')) {
- Log.info();
- Log.info(
- 'πŸ’‘ Get help for this issue at https://remotion.dev/docs/target-closed',
- );
- }
-
- if (err.message.includes('ENAMETOOLONG')) {
- Log.info();
- Log.info(
- 'πŸ’‘ Get help for this issue at https://remotion.dev/docs/enametoolong',
- );
- }
-
- if (err.message.includes('Error creating WebGL context')) {
- Log.info();
- Log.warn(
- 'πŸ’‘ You might need to set the OpenGL renderer to "angle" (or "swangle" if rendering on lambda). Learn why at https://www.remotion.dev/docs/three',
- );
- Log.warn(
- "πŸ’‘ Check how it's done at https://www.remotion.dev/docs/chromium-flags#--gl",
- );
- }
-
- if (err.message.includes('The bucket does not allow ACLs')) {
- Log.info();
- Log.info(
- chalk.green(
- 'πŸ’‘ Fix this issue https://remotion.dev/docs/lambda/troubleshooting/bucket-disallows-acl',
- ),
- );
- }
-
- if (err.message.includes('Minified React error #306')) {
- const componentName = err.message.match(/<\w+>/)?.[0];
- Log.info(
- [
- 'πŸ’‘ This error indicates that the component',
- componentName ? `(${componentName})` : null,
- 'you are trying to render is not imported correctly.',
- ]
- .filter(truthy)
- .join(' '),
- );
-
- Log.info();
- Log.info(
- ' Check the root file and ensure that the component is not undefined.',
- );
- Log.info(
- ' Oftentimes, this happens if the component is missing the `export` keyword',
- );
- Log.info(
- ' or if the component was renamed and the import statement not properly adjusted.',
- );
- }
-
- if (err.message.includes('GLIBC_')) {
- Log.info('πŸ’‘ Remotion requires at least Libc 2.35.');
- Log.info(
- 'πŸ’‘ Get help for this issue: https://github.com/remotion-dev/remotion/issues/2439',
- );
- }
-
- if (err.message.includes('EBADF')) {
- Log.info('πŸ’‘ This error might be fixed by changing your Node version:');
- Log.info(' https://github.com/remotion-dev/remotion/issues/2452');
- }
-};
diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsx
index 5e71330943..95faa7dea4 100644
--- a/packages/cli/src/index.tsx
+++ b/packages/cli/src/index.tsx
@@ -15,7 +15,6 @@ import {getCliOptions} from './get-cli-options';
import {getCompositionWithDimensionOverride} from './get-composition-with-dimension-override';
import {loadConfig} from './get-config-file-name';
import {getFinalOutputCodec} from './get-final-output-codec';
-import {handleCommonError} from './handle-common-errors';
import {getVideoImageFormat} from './image-formats';
import {initializeCli} from './initialize-cli';
import {lambdaCommand} from './lambda-command';
@@ -24,6 +23,7 @@ import {Log} from './log';
import {makeProgressBar} from './make-progress-bar';
import {BooleanFlags, parsedCli, quietFlagProvided} from './parse-command-line';
import {printCompositions} from './print-compositions';
+import {printError} from './print-error';
import {printHelp} from './print-help';
import {createOverwriteableCliOutput} from './progress-bar';
import {render} from './render';
@@ -79,7 +79,7 @@ export const cli = async () => {
await upgrade(
remotionRoot,
parsedCli['package-manager'],
- parsedCli.version,
+ parsedCli.version
);
} else if (command === VERSIONS_COMMAND) {
await versionsCommand(remotionRoot);
@@ -98,10 +98,7 @@ export const cli = async () => {
}
} catch (err) {
Log.info();
- await handleCommonError(
- err as Error,
- ConfigInternals.Logging.getLogLevel(),
- );
+ await printError(err as Error, ConfigInternals.Logging.getLogLevel());
cleanupBeforeQuit();
process.exit(1);
} finally {
@@ -123,7 +120,7 @@ export const CliInternals = {
BooleanFlags,
quietFlagProvided,
parsedCli,
- handleCommonError,
+ printError,
formatBytes,
getFileSizeDownloadBar,
determineFinalStillImageFormat,
diff --git a/packages/cli/src/preview-server/render-queue/queue.ts b/packages/cli/src/preview-server/render-queue/queue.ts
index e2b57c9f35..f10c9281ec 100644
--- a/packages/cli/src/preview-server/render-queue/queue.ts
+++ b/packages/cli/src/preview-server/render-queue/queue.ts
@@ -2,8 +2,8 @@ import path from 'node:path';
import {chalk} from '../../chalk';
import {ConfigInternals} from '../../config';
import {installFileWatcher} from '../../file-watcher';
-import {handleCommonError} from '../../handle-common-errors';
import {Log} from '../../log';
+import {printError} from '../../print-error';
import type {AggregateRenderProgress} from '../../progress-types';
import {initialAggregateRenderProgress} from '../../progress-types';
import {waitForLiveEventsListener} from '../live-events';
@@ -15,7 +15,7 @@ let jobQueue: RenderJobWithCleanup[] = [];
const updateJob = (
id: string,
- updater: (job: RenderJobWithCleanup) => RenderJobWithCleanup,
+ updater: (job: RenderJobWithCleanup) => RenderJobWithCleanup
) => {
jobQueue = jobQueue.map((j) => {
if (id === j.id) {
@@ -243,10 +243,7 @@ const processJobIfPossible = async ({
};
});
- await handleCommonError(
- err as Error,
- ConfigInternals.Logging.getLogLevel(),
- );
+ await printError(err as Error, ConfigInternals.Logging.getLogLevel());
waitForLiveEventsListener().then((listener) => {
listener.sendEventToClient({
diff --git a/packages/cloudrun/src/cli/index.ts b/packages/cloudrun/src/cli/index.ts
index ce87666a37..3a122b7303 100644
--- a/packages/cloudrun/src/cli/index.ts
+++ b/packages/cloudrun/src/cli/index.ts
@@ -58,7 +58,7 @@ export const executeCommand = async (args: string[], remotionRoot: string) => {
} catch (err) {
const error = err as Error;
if (error instanceof RenderInternals.SymbolicateableError) {
- await CliInternals.handleCommonError(
+ await CliInternals.printError(
error,
ConfigInternals.Logging.getLogLevel(),
);
@@ -72,7 +72,7 @@ export const executeCommand = async (args: string[], remotionRoot: string) => {
stack: error.stack,
stackFrame: frames,
});
- await CliInternals.handleCommonError(
+ await CliInternals.printError(
errorWithStackFrame,
ConfigInternals.Logging.getLogLevel(),
);
diff --git a/packages/example/inspect-render.mjs b/packages/example/inspect-render.mjs
index 46800e4eba..5c21dfb613 100644
--- a/packages/example/inspect-render.mjs
+++ b/packages/example/inspect-render.mjs
@@ -23,4 +23,4 @@ const errorWithStackFrame = new RenderInternals.SymbolicateableError({
stackFrame: frames,
});
-await CliInternals.handleCommonError(errorWithStackFrame, 'info');
+await CliInternals.printError(errorWithStackFrame, 'info');
diff --git a/packages/lambda/src/api/render-media-on-lambda.ts b/packages/lambda/src/api/render-media-on-lambda.ts
index 3aba192f20..c41f16d874 100644
--- a/packages/lambda/src/api/render-media-on-lambda.ts
+++ b/packages/lambda/src/api/render-media-on-lambda.ts
@@ -9,8 +9,7 @@ import type {
VideoImageFormat,
X264Preset,
} from '@remotion/renderer';
-import type {BrowserSafeApis} from '@remotion/renderer/client';
-import {wrapWithErrorHandling} from '@remotion/renderer/src/wrap-with-error-handling';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import type {AwsRegion} from '../pricing/aws-regions';
import {callLambda} from '../shared/call-lambda';
import type {OutNameInput, Privacy} from '../shared/constants';
@@ -138,7 +137,7 @@ const renderMediaOnLambdaRaw = async (
* @param params.webhook Configuration for webhook called upon completion or timeout of the render.
* @returns {Promise<RenderMediaOnLambdaOutput>} See documentation for detailed structure
*/
-export const renderMediaOnLambda = wrapWithErrorHandling(
+export const renderMediaOnLambda = BrowserSafeApis.wrapWithErrorHandling(
renderMediaOnLambdaRaw
) as typeof renderMediaOnLambdaRaw;
diff --git a/packages/lambda/src/api/render-still-on-lambda.ts b/packages/lambda/src/api/render-still-on-lambda.ts
index 748d0ad469..a66c46d673 100644
--- a/packages/lambda/src/api/render-still-on-lambda.ts
+++ b/packages/lambda/src/api/render-still-on-lambda.ts
@@ -4,8 +4,7 @@ import type {
StillImageFormat,
ToOptions,
} from '@remotion/renderer';
-import type {BrowserSafeApis} from '@remotion/renderer/client';
-import {wrapWithErrorHandling} from '@remotion/renderer/src/wrap-with-error-handling';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {VERSION} from 'remotion/version';
import type {AwsRegion} from '../pricing/aws-regions';
import {callLambda} from '../shared/call-lambda';
@@ -189,6 +188,6 @@ const renderStillOnLambdaRaw = async ({
* @param params.privacy Whether the item in the S3 bucket should be public. Possible values: `"private"` and `"public"`
* @returns {Promise<RenderStillOnLambdaOutput>} See documentation for exact response structure.
*/
-export const renderStillOnLambda = wrapWithErrorHandling(
+export const renderStillOnLambda = BrowserSafeApis.wrapWithErrorHandling(
renderStillOnLambdaRaw
) as typeof renderStillOnLambdaRaw;
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 3058fbdb8f..e51b69f36b 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -32,11 +32,11 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
if (!serveUrl) {
Log.error('No serve URL passed.');
Log.info(
- 'Pass an additional argument specifying a URL where your Remotion project is hosted.',
+ 'Pass an additional argument specifying a URL where your Remotion project is hosted.'
);
Log.info();
Log.info(
- `${BINARY_NAME} ${RENDER_COMMAND} <serve-url> <composition-id> [output-location]`,
+ `${BINARY_NAME} ${RENDER_COMMAND} <serve-url> <composition-id> [output-location]`
);
quit(1);
}
@@ -80,7 +80,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
if (!serveUrl.startsWith('https://') && !serveUrl.startsWith('http://')) {
throw Error(
- 'Passing the shorthand serve URL without composition name is currently not supported.\n Make sure to pass a composition name after the shorthand serve URL or pass the complete serveURL without composition name to get to choose between all compositions.',
+ 'Passing the shorthand serve URL without composition name is currently not supported.\n Make sure to pass a composition name after the shorthand serve URL or pass the complete serveURL without composition name to get to choose between all compositions.'
);
}
@@ -200,17 +200,17 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
Log.info(
CliInternals.chalk.gray(
- `bucket = ${res.bucketName}, function = ${functionName}`,
- ),
+ `bucket = ${res.bucketName}, function = ${functionName}`
+ )
);
Log.info(
CliInternals.chalk.gray(
- `renderId = ${res.renderId}, codec = ${codec} (${reason})`,
- ),
+ `renderId = ${res.renderId}, codec = ${codec} (${reason})`
+ )
);
const verbose = RenderInternals.isEqualOrBelowLogLevel(
ConfigInternals.Logging.getLogLevel(),
- 'verbose',
+ 'verbose'
);
Log.verbose(`CloudWatch logs (if enabled): ${res.cloudWatchLogs}`);
@@ -232,7 +232,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
totalFrames: getTotalFrames(status),
timeToEncode: status.timeToEncode,
}),
- false,
+ false
);
// eslint-disable-next-line no-constant-condition
@@ -255,7 +255,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
timeToEncode: newStatus.timeToEncode,
totalFrames: getTotalFrames(newStatus),
}),
- false,
+ false
);
if (newStatus.done) {
@@ -269,7 +269,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
timeToEncode: newStatus.timeToEncode,
totalFrames: getTotalFrames(newStatus),
}),
- false,
+ false
);
if (downloadName) {
const downloadStart = Date.now();
@@ -293,7 +293,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
timeToEncode: newStatus.timeToEncode,
totalFrames: getTotalFrames(newStatus),
}),
- false,
+ false
);
},
});
@@ -311,7 +311,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
timeToEncode: newStatus.timeToEncode,
totalFrames: getTotalFrames(newStatus),
}),
- false,
+ false
);
Log.info();
Log.info();
@@ -333,7 +333,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
`Estimated cost $${newStatus.costs.displayCost}`,
]
.filter(Boolean)
- .join(', '),
+ .join(', ')
);
if (newStatus.mostExpensiveFrameRanges) {
Log.verbose('Most expensive frame ranges:');
@@ -342,7 +342,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
.map((f) => {
return `${f.frameRange[0]}-${f.frameRange[1]} (${f.timeInMilliseconds}ms)`;
})
- .join(', '),
+ .join(', ')
);
}
@@ -371,15 +371,15 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
stack: err.stack,
stackFrame: frames,
});
- await CliInternals.handleCommonError(errorWithStackFrame, logLevel);
+ await CliInternals.printError(errorWithStackFrame, logLevel);
}
Log.info();
Log.info(
- `Accrued costs until error was thrown: ${newStatus.costs.displayCost}.`,
+ `Accrued costs until error was thrown: ${newStatus.costs.displayCost}.`
);
Log.info(
- 'This is an estimate and continuing Lambda functions may incur additional costs.',
+ 'This is an estimate and continuing Lambda functions may incur additional costs.'
);
quit(1);
}
@@ -390,7 +390,7 @@ function getTotalFrames(status: RenderProgress): number | null {
return status.renderMetadata
? RenderInternals.getFramesToRender(
status.renderMetadata.frameRange,
- status.renderMetadata.everyNthFrame,
+ status.renderMetadata.everyNthFrame
).length
: null;
}
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index 3f8049fa4b..145f3be711 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -126,7 +126,7 @@ export const executeCommand = async (args: string[], remotionRoot: string) => {
const error = err as Error;
if (
error.message.includes(
- 'The role defined for the function cannot be assumed by Lambda',
+ 'The role defined for the function cannot be assumed by Lambda'
)
) {
if (parsedLambdaCli['custom-role-arn']) {
@@ -137,7 +137,7 @@ export const executeCommand = async (args: string[], remotionRoot: string) => {
- Make sure the role has the same policy assigned as the one returned by "npx ${BINARY_NAME} ${POLICIES_COMMAND} ${ROLE_SUBCOMMAND}"
Revisit ${DOCS_URL}/docs/lambda/setup and make sure you set up the role and role policy correctly. Also see the troubleshooting page: ${DOCS_URL}/docs/lambda/troubleshooting/permissions. The original error message is:
- `.trim(),
+ `.trim()
);
}
@@ -148,7 +148,7 @@ The role "${ROLE_NAME}" does not exist in your AWS account or has the wrong poli
- The policy is not exactly as specified in the setup guide
Revisit ${DOCS_URL}/docs/lambda/setup and make sure you set up the role and role policy correctly. Also see the troubleshooting page: ${DOCS_URL}/docs/lambda/troubleshooting/permissions. The original error message is:
-`.trim(),
+`.trim()
);
}
@@ -156,7 +156,7 @@ Revisit ${DOCS_URL}/docs/lambda/setup and make sure you set up the role and role
Log.error(
`
AWS returned an "AccessDenied" error message meaning a permission is missing. Read the permissions troubleshooting page: ${DOCS_URL}/docs/lambda/troubleshooting/permissions. The original error message is:
-`.trim(),
+`.trim()
);
}
@@ -164,26 +164,26 @@ AWS returned an "AccessDenied" error message meaning a permission is missing. Re
Log.error(
`
AWS returned an "TooManyRequestsException" error message which could mean you reached the concurrency limit of AWS Lambda. You can increase the limit - read this troubleshooting page: ${DOCS_URL}/docs/lambda/troubleshooting/rate-limit. The original error message is:
-`.trim(),
+`.trim()
);
}
if (
error.stack?.includes(
- 'The security token included in the request is invalid',
+ 'The security token included in the request is invalid'
)
) {
Log.error(
`
AWS returned an error message "The security token included in the request is invalid". A possible reason for this is that you did not enable the region in your AWS account under "Account". The original message is:
-`,
+`
);
}
if (error instanceof RenderInternals.SymbolicateableError) {
- await CliInternals.handleCommonError(
+ await CliInternals.printError(
error,
- ConfigInternals.Logging.getLogLevel(),
+ ConfigInternals.Logging.getLogLevel()
);
} else {
const frames = RenderInternals.parseStack(error.stack?.split('\n') ?? []);
@@ -195,9 +195,9 @@ AWS returned an error message "The security token included in the request is inv
stack: error.stack,
stackFrame: frames,
});
- await CliInternals.handleCommonError(
+ await CliInternals.printError(
errorWithStackFrame,
- ConfigInternals.Logging.getLogLevel(),
+ ConfigInternals.Logging.getLogLevel()
);
}