Skip to content

🎥 Make videos programmatically with React

better logging of errors

Jonny Burgerefc4bc44f020
diff --git a/packages/lambda/src/api/render-still-on-lambda.ts b/packages/lambda/src/api/render-still-on-lambda.ts
index 0076c4eb59..a656e7ca75 100644
--- a/packages/lambda/src/api/render-still-on-lambda.ts
+++ b/packages/lambda/src/api/render-still-on-lambda.ts
@@ -57,6 +57,7 @@ export const renderStillOnLambda = async ({
maxRetries: maxRetries ?? 3,
frame: frame ?? 0,
privacy,
+ attempt: 1,
},
region,
});
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index e7bbebb6da..ddcabc73f3 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -157,6 +157,17 @@ export const renderCommand = async (args: string[]) => {
}
if (newStatus.fatalErrorEncountered) {
+ for (const err of newStatus.errors) {
+ const attemptString = `(Attempt ${err.attempt}/${err.totalAttempts})`;
+ if (err.chunk === null) {
+ Log.error('Error occured while preparing video: ' + attemptString);
+ } else {
+ Log.error('Error occurred when rendering chunk ' + err.chunk);
+ }
+
+ Log.error(err.stack);
+ }
+
Log.error(JSON.stringify(newStatus.errors));
Log.error('Fatal error encountered. Exiting.');
process.exit(1);
diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.ts
index 5a8aace4d5..c6d7157fd6 100644
--- a/packages/lambda/src/functions/helpers/get-progress.ts
+++ b/packages/lambda/src/functions/helpers/get-progress.ts
@@ -21,7 +21,6 @@ import {getRenderMetadata} from './get-render-metadata';
import {getTimeToFinish} from './get-time-to-finish';
import {inspectErrors} from './inspect-errors';
import {lambdaLs} from './io';
-import {isFatalError} from './is-fatal-error';
export const getProgress = async ({
bucketName,
@@ -183,7 +182,7 @@ export const getProgress = async ({
outputFile: outputFile?.url ?? null,
timeToFinish,
errors: errorExplanations,
- fatalErrorEncountered: errorExplanations.some(isFatalError),
+ fatalErrorEncountered: errorExplanations.some((f) => f.isFatal),
currentTime: Date.now(),
renderSize,
lambdasInvoked: lambdasInvokedStats.lambdasInvoked,
diff --git a/packages/lambda/src/functions/helpers/is-fatal-error.ts b/packages/lambda/src/functions/helpers/is-fatal-error.ts
deleted file mode 100644
index 13b6f16ea5..0000000000
--- a/packages/lambda/src/functions/helpers/is-fatal-error.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import {LambdaErrorInfo} from './write-lambda-error';
-
-export const isFatalError = (err: LambdaErrorInfo) => {
- return err.isFatal;
-};
diff --git a/packages/lambda/src/functions/helpers/write-lambda-error.ts b/packages/lambda/src/functions/helpers/write-lambda-error.ts
index 9ba1a658ce..008450dac1 100644
--- a/packages/lambda/src/functions/helpers/write-lambda-error.ts
+++ b/packages/lambda/src/functions/helpers/write-lambda-error.ts
@@ -11,6 +11,9 @@ export type LambdaErrorInfo = {
frame: number | null;
chunk: number | null;
isFatal: boolean;
+ attempt: number;
+ willRetry: boolean;
+ totalAttempts: number;
tmpDir: {files: FileNameAndSize[]; total: number} | null;
};
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index b652e0f8c9..927cbdd047 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -124,6 +124,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
quality: params.quality,
privacy: params.privacy,
saveBrowserLogs: params.saveBrowserLogs,
+ attempt: 1,
};
return payload;
});
@@ -227,6 +228,9 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
}`,
tmpDir: null,
type: 'stitcher',
+ attempt: 1,
+ totalAttempts: 1,
+ willRetry: false,
},
renderId: params.renderId,
expectedBucketOwner: options.expectedBucketOwner,
@@ -384,6 +388,9 @@ export const launchHandler = async (
type: 'stitcher',
isFatal: true,
tmpDir: getTmpDirStateIfENoSp((err as Error).stack as string),
+ attempt: 1,
+ totalAttempts: 1,
+ willRetry: false,
},
expectedBucketOwner: options.expectedBucketOwner,
renderId: params.renderId,
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 39f9f09c47..706ebec6a7 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -231,7 +231,8 @@ export const rendererHandler = async (
(err as Error).message.includes(
'error while loading shared libraries: libnss3.so'
);
- if (isBrowserError || params.retriesLeft > 0) {
+ const willRetry = isBrowserError || params.retriesLeft > 0;
+ if (willRetry) {
const retryPayload: LambdaPayloads[LambdaRoutines.renderer] = {
...params,
retriesLeft: params.retriesLeft - 1,
@@ -257,6 +258,9 @@ export const rendererHandler = async (
type: 'renderer',
isFatal: !isBrowserError,
tmpDir: getTmpDirStateIfENoSp((err as Error).stack as string),
+ attempt: params.attempt,
+ totalAttempts: params.retriesLeft + params.attempt,
+ willRetry,
},
renderId: params.renderId,
expectedBucketOwner: options.expectedBucketOwner,
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index ced088e0a0..2a7502da00 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -162,7 +162,8 @@ export const stillHandler = async (
(err as Error).message.includes(
'error while loading shared libraries: libnss3.so'
);
- if (isBrowserError || params.maxRetries > 0) {
+ const willRetry = isBrowserError || params.maxRetries > 0;
+ if (willRetry) {
const retryPayload: LambdaPayloads[LambdaRoutines.still] = {
...params,
maxRetries: params.maxRetries - 1,
@@ -190,6 +191,9 @@ export const stillHandler = async (
(err as Error).stack) as string,
type: 'browser',
tmpDir: getTmpDirStateIfENoSp((err as Error).stack as string),
+ attempt: params.attempt,
+ totalAttempts: params.attempt + params.maxRetries,
+ willRetry,
},
expectedBucketOwner: options.expectedBucketOwner,
renderId,
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index a4147d52be..fd33642a78 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -198,6 +198,7 @@ export type LambdaPayloads = {
envVariables: Record<string, string> | undefined;
privacy: Privacy;
saveBrowserLogs: boolean;
+ attempt: number;
};
still: {
type: LambdaRoutines.still;
@@ -206,6 +207,7 @@ export type LambdaPayloads = {
inputProps: unknown;
imageFormat: ImageFormat;
envVariables: Record<string, string> | undefined;
+ attempt: number;
quality: number | undefined;
maxRetries: number;
frame: number;