Skip to content

🎥 Make videos programmatically with React

fix tests

Jonny Burgera5a2e27dcdcd
diff --git a/packages/lambda/src/functions/index.ts b/packages/lambda/src/functions/index.ts
index 31d48e842c..b723e3d52c 100644
--- a/packages/lambda/src/functions/index.ts
+++ b/packages/lambda/src/functions/index.ts
@@ -1,7 +1,6 @@
import {RenderInternals} from '@remotion/renderer';
import type {LambdaPayload} from '../shared/constants';
import {COMMAND_NOT_FOUND, LambdaRoutines} from '../shared/constants';
-import type {OrError} from '../shared/return-values';
import {compositionsHandler} from './compositions';
import {deleteTmpDir} from './helpers/clean-tmpdir';
import {getWarm, setWarm} from './helpers/is-warm';
@@ -250,6 +249,14 @@ const innerHandler = async ({
throw new Error(COMMAND_NOT_FOUND);
};
+export type OrError<T> =
+ | T
+ | {
+ type: 'error';
+ message: string;
+ stack: string;
+ };
+
const routine = async (
params: LambdaPayload,
responseStream: ResponseStream,
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index f9e1f782ec..2cefaea203 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -576,7 +576,7 @@ export const launchHandler = async (
willRetry: false,
message: (err as Error).message,
});
- overallProgress.upload();
+ await overallProgress.upload();
RenderInternals.Log.error(
{indent: false, logLevel: params.logLevel},
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index 1b70faed89..f6c58149cc 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -304,7 +304,11 @@ export type RenderStillLambdaResponsePayload = {
renderId: string;
};
-export const stillHandler = async (options: Options): Promise<void> => {
+export const stillHandler = async (
+ options: Options,
+): Promise<{
+ type: 'success';
+}> => {
const {params} = options;
if (params.type !== LambdaRoutines.still) {
@@ -313,6 +317,7 @@ export const stillHandler = async (options: Options): Promise<void> => {
try {
await innerStillHandler(options);
+ return {type: 'success'};
} catch (err) {
// If this error is encountered, we can just retry as it
// is a very rare error to occur
diff --git a/packages/lambda/src/shared/call-lambda.ts b/packages/lambda/src/shared/call-lambda.ts
index 5a3c13dbea..89959341f2 100644
--- a/packages/lambda/src/shared/call-lambda.ts
+++ b/packages/lambda/src/shared/call-lambda.ts
@@ -5,6 +5,7 @@ import {
InvokeWithResponseStreamCommand,
} from '@aws-sdk/client-lambda';
import {NoReactAPIs} from '@remotion/renderer/pure';
+import type {OrError} from '../functions';
import type {
MessageTypeId,
OnMessage,
@@ -46,6 +47,12 @@ export const callLambda = async <T extends LambdaRoutines>(
try {
// Do not remove this await
const res = await callLambdaWithoutRetry<T>(options);
+ if (res.type === 'error') {
+ const err = new Error(res.message);
+ err.stack = res.stack;
+ throw err;
+ }
+
return res;
} catch (err) {
if (options.retriesRemaining === 0) {
@@ -94,7 +101,7 @@ const callLambdaWithoutRetry = async <T extends LambdaRoutines>({
payload,
region,
timeoutInTest,
-}: Options<T>): Promise<LambdaReturnValues[T]> => {
+}: Options<T>): Promise<OrError<LambdaReturnValues[T]>> => {
const Payload = JSON.stringify({type, ...payload});
const res = await getLambdaClient(region, timeoutInTest).send(
new InvokeCommand({
@@ -107,7 +114,7 @@ const callLambdaWithoutRetry = async <T extends LambdaRoutines>({
const decoded = new TextDecoder('utf-8').decode(res.Payload);
try {
- return JSON.parse(decoded) as LambdaReturnValues[T];
+ return JSON.parse(decoded) as OrError<LambdaReturnValues[T]>;
} catch (err) {
throw new Error(`Invalid JSON (${type}): ${JSON.stringify(decoded)}`);
}
diff --git a/packages/lambda/src/shared/return-values.ts b/packages/lambda/src/shared/return-values.ts
index 902d0052b3..bcf2aa0d8e 100644
--- a/packages/lambda/src/shared/return-values.ts
+++ b/packages/lambda/src/shared/return-values.ts
@@ -7,14 +7,6 @@ import type {startHandler} from '../functions/start';
import type {stillHandler} from '../functions/still';
import type {LambdaRoutines} from './constants';
-export type OrError<T> =
- | T
- | {
- type: 'error';
- message: string;
- stack: string;
- };
-
export interface LambdaReturnValues {
[LambdaRoutines.start]: ReturnType<typeof startHandler>;
[LambdaRoutines.launch]: ReturnType<typeof launchHandler>;
diff --git a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
index 738d2de792..d5dd81568d 100644
--- a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
+++ b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
@@ -53,7 +53,7 @@ test('Should make a transparent video', async () => {
prefix: rendersPrefix(renderId),
});
- expect(files.length).toBe(4);
+ expect(files.length).toBe(2);
await deleteRender({
bucketName: progress.outBucket as string,