Skip to content

🎥 Make videos programmatically with React

inline errors

Jonny Burger0fd07e64cc17
diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.ts
index 75d85c9c51..04f53b78e7 100644
--- a/packages/lambda/src/functions/helpers/get-progress.ts
+++ b/packages/lambda/src/functions/helpers/get-progress.ts
@@ -3,20 +3,15 @@ import {NoReactInternals} from 'remotion/no-react';
import type {AwsRegion} from '../../pricing/aws-regions';
import type {CustomCredentials} from '../../shared/aws-clients';
import type {CleanupInfo, RenderProgress} from '../../shared/constants';
-import {
- MAX_EPHEMERAL_STORAGE_IN_MB,
- rendersPrefix,
-} from '../../shared/constants';
+import {MAX_EPHEMERAL_STORAGE_IN_MB} from '../../shared/constants';
import {truthy} from '../../shared/truthy';
import {calculateChunkTimes} from './calculate-chunk-times';
import {estimatePriceFromBucket} from './calculate-price-from-bucket';
import {getExpectedOutName} from './expected-out-name';
import {formatCostsInfo} from './format-costs-info';
-import {getCurrentRegionInFunction} from './get-current-region';
import {getOverallProgress} from './get-overall-progress';
import {getOverallProgressS3} from './get-overall-progress-s3';
import {inspectErrors} from './inspect-errors';
-import {lambdaLs} from './io';
import {makeTimeoutError} from './make-timeout-error';
import {lambdaRenderHasAudioVideo} from './render-has-audio-video';
import type {EnhancedErrorInfo} from './write-lambda-error';
@@ -113,21 +108,10 @@ export const getProgress = async ({
};
}
- const contents = await lambdaLs({
- bucketName,
- prefix: rendersPrefix(renderId),
- region: getCurrentRegionInFunction(),
- expectedBucketOwner,
- });
-
const {renderMetadata} = overallProgress;
- const errorExplanations = await inspectErrors({
- contents,
- renderId,
- bucket: bucketName,
- region: getCurrentRegionInFunction(),
- expectedBucketOwner,
+ const errorExplanations = inspectErrors({
+ errors: overallProgress.errors,
});
if (renderMetadata && renderMetadata.type === 'still') {
diff --git a/packages/lambda/src/functions/helpers/inspect-errors.ts b/packages/lambda/src/functions/helpers/inspect-errors.ts
index 9a688c8eb8..ddd082362c 100644
--- a/packages/lambda/src/functions/helpers/inspect-errors.ts
+++ b/packages/lambda/src/functions/helpers/inspect-errors.ts
@@ -1,10 +1,4 @@
-import type {_Object} from '@aws-sdk/client-s3';
-import {NoReactInternals} from 'remotion/no-react';
-import type {AwsRegion} from '../../pricing/aws-regions';
-import {getErrorKeyPrefix} from '../../shared/constants';
import {DOCS_URL} from '../../shared/docs-url';
-import {streamToString} from '../../shared/stream-to-string';
-import {lambdaReadFile} from './io';
import {
errorIsOutOfSpaceError,
isBrowserCrashedError,
@@ -48,47 +42,16 @@ const getExplanation = (stack: string) => {
return null;
};
-export const inspectErrors = async ({
- contents,
- bucket,
- region,
- renderId,
- expectedBucketOwner,
+export const inspectErrors = ({
+ errors,
}: {
- contents: _Object[];
- bucket: string;
- region: AwsRegion;
- renderId: string;
- expectedBucketOwner: string;
-}): Promise<EnhancedErrorInfo[]> => {
- const errs = contents
- .filter((c) => c.Key?.startsWith(getErrorKeyPrefix(renderId)))
- .map((c) => c.Key)
- .filter(NoReactInternals.truthy);
-
- if (errs.length === 0) {
- return [];
- }
-
- const errors = await Promise.all(
- errs.map(async (key) => {
- const Body = await lambdaReadFile({
- bucketName: bucket,
- key,
- region,
- expectedBucketOwner,
- });
- const errorLog = await streamToString(Body);
- return errorLog;
- }),
- );
- return errors.map((e, index): EnhancedErrorInfo => {
- const parsed = JSON.parse(e) as LambdaErrorInfo;
-
+ errors: LambdaErrorInfo[];
+}): EnhancedErrorInfo[] => {
+ return errors.map((e): EnhancedErrorInfo => {
return {
- ...parsed,
- explanation: getExplanation(parsed.stack),
- s3Location: errs[index],
+ ...e,
+ explanation: getExplanation(e.stack),
+ s3Location: '',
};
});
};
diff --git a/packages/lambda/src/functions/helpers/merge-chunks.ts b/packages/lambda/src/functions/helpers/merge-chunks.ts
index adefddd609..f6aa6680a8 100644
--- a/packages/lambda/src/functions/helpers/merge-chunks.ts
+++ b/packages/lambda/src/functions/helpers/merge-chunks.ts
@@ -11,7 +11,6 @@ import type {
RenderMetadata,
SerializedInputProps,
} from '../../shared/constants';
-import {rendersPrefix} from '../../shared/constants';
import type {DownloadBehavior} from '../../shared/content-disposition-header';
import type {LambdaCodec} from '../../shared/validate-lambda-codec';
import {concatVideos} from './concat-videos';
@@ -19,7 +18,7 @@ import {createPostRenderData} from './create-post-render-data';
import {getCurrentRegionInFunction} from './get-current-region';
import {getOutputUrlFromMetadata} from './get-output-url-from-metadata';
import {inspectErrors} from './inspect-errors';
-import {lambdaLs, lambdaWriteFile} from './io';
+import {lambdaWriteFile} from './io';
import type {OverallProgressHelper} from './overall-render-progress';
import {timer} from './timer';
@@ -101,19 +100,8 @@ export const mergeChunksAndFinishRender = async (options: {
writeToS3.end();
- const contents = await lambdaLs({
- bucketName: options.bucketName,
- prefix: rendersPrefix(options.renderId),
- expectedBucketOwner: options.expectedBucketOwner,
- region: getCurrentRegionInFunction(),
- });
-
- const errorExplanationsProm = inspectErrors({
- contents,
- renderId: options.renderId,
- bucket: options.bucketName,
- region: getCurrentRegionInFunction(),
- expectedBucketOwner: options.expectedBucketOwner,
+ const errorExplanations = inspectErrors({
+ errors: options.overallProgress.get().errors,
});
const cleanupSerializedInputPropsProm = cleanupSerializedInputProps({
@@ -137,7 +125,7 @@ export const mergeChunksAndFinishRender = async (options: {
region: getCurrentRegionInFunction(),
memorySizeInMb: Number(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE),
renderMetadata: options.renderMetadata,
- errorExplanations: await errorExplanationsProm,
+ errorExplanations,
timeToEncode: encodingStop - encodingStart,
timeToDelete: (
await Promise.all([
diff --git a/packages/lambda/src/functions/helpers/write-lambda-error.ts b/packages/lambda/src/functions/helpers/write-lambda-error.ts
index 32f4a1a264..4f5d3a30ed 100644
--- a/packages/lambda/src/functions/helpers/write-lambda-error.ts
+++ b/packages/lambda/src/functions/helpers/write-lambda-error.ts
@@ -1,8 +1,5 @@
-import {getErrorFileName} from '../../shared/constants';
-import {getCurrentRegionInFunction} from './get-current-region';
import type {FileNameAndSize} from './get-files-in-folder';
import {getFolderFiles} from './get-files-in-folder';
-import {lambdaWriteFile} from './io';
import {errorIsOutOfSpaceError} from './is-enosp-err';
export type LambdaErrorInfo = {
@@ -38,33 +35,9 @@ export const getTmpDirStateIfENoSp = (
};
export type EnhancedErrorInfo = LambdaErrorInfo & {
+ /**
+ * @deprecated Will always be an empty string.
+ */
s3Location: string;
explanation: string | null;
};
-
-export const writeLambdaError = async ({
- bucketName,
- renderId,
- errorInfo,
- expectedBucketOwner,
-}: {
- bucketName: string;
- renderId: string;
- expectedBucketOwner: string;
- errorInfo: LambdaErrorInfo;
-}) => {
- await lambdaWriteFile({
- bucketName,
- key: `${getErrorFileName({
- renderId,
- chunk: errorInfo.chunk,
- attempt: errorInfo.attempt,
- })}.txt`,
- body: JSON.stringify(errorInfo),
- region: getCurrentRegionInFunction(),
- privacy: 'private',
- expectedBucketOwner,
- downloadBehavior: null,
- customCredentials: null,
- });
-};
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index 8ce5621a8d..cca312078a 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -40,13 +40,11 @@ import {
} from './helpers/get-browser-instance';
import {getCurrentRegionInFunction} from './helpers/get-current-region';
import {mergeChunksAndFinishRender} from './helpers/merge-chunks';
+import type {OverallProgressHelper} from './helpers/overall-render-progress';
import {makeOverallRenderProgress} from './helpers/overall-render-progress';
import {streamRendererFunctionWithRetry} from './helpers/stream-renderer';
import {validateComposition} from './helpers/validate-composition';
-import {
- getTmpDirStateIfENoSp,
- writeLambdaError,
-} from './helpers/write-lambda-error';
+import {getTmpDirStateIfENoSp} from './helpers/write-lambda-error';
type Options = {
expectedBucketOwner: string;
@@ -57,22 +55,17 @@ const innerLaunchHandler = async ({
functionName,
params,
options,
+ overallProgress,
}: {
functionName: string;
params: LambdaPayload;
options: Options;
+ overallProgress: OverallProgressHelper;
}): Promise<PostRenderData> => {
if (params.type !== LambdaRoutines.launch) {
throw new Error('Expected launch type');
}
- const overallProgress = makeOverallRenderProgress({
- renderId: params.renderId,
- bucketName: params.bucketName,
- expectedBucketOwner: options.expectedBucketOwner,
- region: getCurrentRegionInFunction(),
- });
-
const startedDate = Date.now();
const browserInstance = getBrowserInstance(
@@ -446,24 +439,20 @@ export const launchHandler = async (
err,
);
- await writeLambdaError({
- bucketName: params.bucketName,
- errorInfo: {
- type: 'webhook',
- message: (err as Error).message,
- name: (err as Error).name as string,
- stack: (err as Error).stack as string,
- tmpDir: null,
- frame: 0,
- chunk: 0,
- isFatal: false,
- attempt: 1,
- willRetry: false,
- totalAttempts: 1,
- },
- renderId: params.renderId,
- expectedBucketOwner: options.expectedBucketOwner,
+ overallProgress.addErrorWithoutUpload({
+ type: 'webhook',
+ message: (err as Error).message,
+ name: (err as Error).name as string,
+ stack: (err as Error).stack as string,
+ tmpDir: null,
+ frame: 0,
+ chunk: 0,
+ isFatal: false,
+ attempt: 1,
+ willRetry: false,
+ totalAttempts: 1,
});
+ overallProgress.upload();
}
};
@@ -481,11 +470,19 @@ export const launchHandler = async (
)} before it times out`,
);
+ const overallProgress = makeOverallRenderProgress({
+ renderId: params.renderId,
+ bucketName: params.bucketName,
+ expectedBucketOwner: options.expectedBucketOwner,
+ region: getCurrentRegionInFunction(),
+ });
+
try {
const postRenderData = await innerLaunchHandler({
functionName,
params,
options,
+ overallProgress,
});
clearTimeout(webhookDueToTimeout);
@@ -522,24 +519,21 @@ export const launchHandler = async (
throw err;
}
- await writeLambdaError({
- bucketName: params.bucketName,
- errorInfo: {
- type: 'webhook',
- message: (err as Error).message,
- name: (err as Error).name as string,
- stack: (err as Error).stack as string,
- tmpDir: null,
- frame: 0,
- chunk: 0,
- isFatal: false,
- attempt: 1,
- willRetry: false,
- totalAttempts: 1,
- },
- renderId: params.renderId,
- expectedBucketOwner: options.expectedBucketOwner,
+ overallProgress.addErrorWithoutUpload({
+ type: 'webhook',
+ message: (err as Error).message,
+ name: (err as Error).name as string,
+ stack: (err as Error).stack as string,
+ tmpDir: null,
+ frame: 0,
+ chunk: 0,
+ isFatal: false,
+ attempt: 1,
+ willRetry: false,
+ totalAttempts: 1,
});
+ overallProgress.upload();
+
RenderInternals.Log.error(
{indent: false, logLevel: params.logLevel},
'Failed to invoke webhook:',
@@ -563,24 +557,21 @@ export const launchHandler = async (
'Error occurred',
err,
);
- await writeLambdaError({
- bucketName: params.bucketName,
- errorInfo: {
- chunk: null,
- frame: null,
- name: (err as Error).name as string,
- stack: (err as Error).stack as string,
- type: 'stitcher',
- isFatal: true,
- tmpDir: getTmpDirStateIfENoSp((err as Error).stack as string),
- attempt: 1,
- totalAttempts: 1,
- willRetry: false,
- message: (err as Error).message,
- },
- expectedBucketOwner: options.expectedBucketOwner,
- renderId: params.renderId,
+ overallProgress.addErrorWithoutUpload({
+ chunk: null,
+ frame: null,
+ name: (err as Error).name as string,
+ stack: (err as Error).stack as string,
+ type: 'stitcher',
+ isFatal: true,
+ tmpDir: getTmpDirStateIfENoSp((err as Error).stack as string),
+ attempt: 1,
+ totalAttempts: 1,
+ willRetry: false,
+ message: (err as Error).message,
});
+ overallProgress.upload();
+
RenderInternals.Log.error(
{indent: false, logLevel: params.logLevel},
'Wrote error to S3',
@@ -615,24 +606,21 @@ export const launchHandler = async (
throw error;
}
- await writeLambdaError({
- bucketName: params.bucketName,
- errorInfo: {
- type: 'webhook',
- message: (err as Error).message,
- name: (err as Error).name as string,
- stack: (err as Error).stack as string,
- tmpDir: null,
- frame: 0,
- chunk: 0,
- isFatal: false,
- attempt: 1,
- willRetry: false,
- totalAttempts: 1,
- },
- renderId: params.renderId,
- expectedBucketOwner: options.expectedBucketOwner,
+ overallProgress.addErrorWithoutUpload({
+ type: 'webhook',
+ message: (err as Error).message,
+ name: (err as Error).name as string,
+ stack: (err as Error).stack as string,
+ tmpDir: null,
+ frame: 0,
+ chunk: 0,
+ isFatal: false,
+ attempt: 1,
+ willRetry: false,
+ totalAttempts: 1,
});
+ overallProgress.upload();
+
RenderInternals.Log.error(
{indent: false, logLevel: params.logLevel},
'Failed to invoke webhook:',
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index 4a2b6897ac..a9da3ece71 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -59,30 +59,6 @@ export const rendersPrefix = (renderId: string) => `renders/${renderId}`;
export const overallProgressKey = (renderId: string) =>
`${rendersPrefix(renderId)}/overall-progress.json`;
-export const lambdaLogsPrefix = (
- renderId: string,
- chunk: number,
- startFrame: number,
- endFrame: number,
-) =>
- `${rendersPrefix(renderId)}/logs/chunk:${String(chunk).padStart(
- 8,
- '0',
- )}:frames:${startFrame}-${endFrame}.json`;
-
-export const getErrorKeyPrefix = (renderId: string) =>
- `${rendersPrefix(renderId)}/errors/`;
-
-export const getErrorFileName = ({
- renderId,
- chunk,
- attempt,
-}: {
- renderId: string;
- chunk: number | null;
- attempt: number;
-}) => getErrorKeyPrefix(renderId) + ':chunk-' + chunk + ':attempt-' + attempt;
-
export type OutNameInput =
| string
| {