Skip to content

🎥 Make videos programmatically with React

log errors in CLI

Jonny Burgere64f19543fde
diff --git a/packages/lambda/src/api/render-still-on-lambda.ts b/packages/lambda/src/api/render-still-on-lambda.ts
index 333b174941..a9b96593a2 100644
--- a/packages/lambda/src/api/render-still-on-lambda.ts
+++ b/packages/lambda/src/api/render-still-on-lambda.ts
@@ -141,9 +141,6 @@ export const renderStillOnLambda = async ({
},
region,
});
- if (res.type === 'error') {
- throw new Error(res.stack);
- }
return {
estimatedPrice: res.estimatedPrice,
diff --git a/packages/lambda/src/functions/index.ts b/packages/lambda/src/functions/index.ts
index 8687c93a5c..2b399396b5 100644
--- a/packages/lambda/src/functions/index.ts
+++ b/packages/lambda/src/functions/index.ts
@@ -46,24 +46,11 @@ export const handler = streamifyResponse(
inputProps: JSON.stringify(params.inputProps),
isWarm,
});
- try {
- const response = await stillHandler(params, renderId, {
- expectedBucketOwner: currentUserId,
- });
- responseStream.write(JSON.stringify(response));
- responseStream.end();
- } catch (err) {
- RenderInternals.Log.error(err);
-
- const response = {
- type: 'error',
- message: (err as Error).message,
- stack: (err as Error).stack,
- };
-
- responseStream.write(JSON.stringify(response));
- responseStream.end();
- }
+ const response = await stillHandler(params, renderId, {
+ expectedBucketOwner: currentUserId,
+ });
+ responseStream.write(JSON.stringify(response));
+ responseStream.end();
return;
}
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index 2da612933d..87c183a3e4 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -1,4 +1,3 @@
-import {InvokeCommand} from '@aws-sdk/client-lambda';
import type {StillImageFormat} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
import fs from 'node:fs';
@@ -6,7 +5,6 @@ import path from 'node:path';
import {VERSION} from 'remotion/version';
import {estimatePrice} from '../api/estimate-price';
import {getOrCreateBucket} from '../api/get-or-create-bucket';
-import {getLambdaClient} from '../shared/aws-clients';
import {cleanupSerializedInputProps} from '../shared/cleanup-serialized-input-props';
import type {
LambdaPayload,
@@ -40,6 +38,7 @@ import {
} from './helpers/write-lambda-error';
import {decompressInputProps} from '../shared/compress-props';
import {Internals} from 'remotion';
+import {callLambda} from '../shared/call-lambda';
type Options = {
expectedBucketOwner: string;
@@ -267,54 +266,53 @@ export const stillHandler = async (
'error while loading shared libraries: libnss3.so'
);
const willRetry = isBrowserError || params.maxRetries > 0;
- if (willRetry) {
- const retryPayload: LambdaPayloads[LambdaRoutines.still] = {
- ...params,
- maxRetries: params.maxRetries - 1,
- attempt: params.attempt + 1,
- };
- const res = await getLambdaClient(getCurrentRegionInFunction()).send(
- new InvokeCommand({
- FunctionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
- // @ts-expect-error
- Payload: JSON.stringify(retryPayload),
- })
- );
- const bucketName =
- params.bucketName ??
- (
- await getOrCreateBucket({
- region: getCurrentRegionInFunction(),
- })
- ).bucketName;
-
- // `await` elided on purpose here; using `void` to mark it as intentional
- // eslint-disable-next-line no-void
- void writeLambdaError({
- bucketName,
- errorInfo: {
- chunk: null,
- frame: null,
- isFatal: false,
- name: (err as Error).name,
- message: (err as Error).message,
- stack: (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,
- });
- const str = JSON.parse(
- Buffer.from(res.Payload as Uint8Array).toString()
- ) as ReturnType<typeof innerStillHandler>;
- return str;
+ console.log({willRetry});
+ if (!willRetry) {
+ throw err;
}
- throw err;
+ const retryPayload: LambdaPayloads[LambdaRoutines.still] = {
+ ...params,
+ maxRetries: params.maxRetries - 1,
+ attempt: params.attempt + 1,
+ };
+
+ const res = await callLambda({
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME as string,
+ payload: retryPayload,
+ region: getCurrentRegionInFunction(),
+ type: LambdaRoutines.still,
+ });
+ const bucketName =
+ params.bucketName ??
+ (
+ await getOrCreateBucket({
+ region: getCurrentRegionInFunction(),
+ })
+ ).bucketName;
+
+ // `await` elided on purpose here; using `void` to mark it as intentional
+ // eslint-disable-next-line no-void
+ void writeLambdaError({
+ bucketName,
+ errorInfo: {
+ chunk: null,
+ frame: null,
+ isFatal: false,
+ name: (err as Error).name,
+ message: (err as Error).message,
+ stack: (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,
+ });
+
+ return res;
}
};
diff --git a/packages/lambda/src/shared/return-values.ts b/packages/lambda/src/shared/return-values.ts
index 0cc3f9a2db..4d59e3308a 100644
--- a/packages/lambda/src/shared/return-values.ts
+++ b/packages/lambda/src/shared/return-values.ts
@@ -7,21 +7,13 @@ import type {startHandler} from '../functions/start';
import type {stillHandler} from '../functions/still';
import type {LambdaRoutines} from './constants';
-type OrError<T> =
- | T
- | {
- type: 'error';
- message: string;
- stack: string;
- };
-
export interface LambdaReturnValues {
[LambdaRoutines.start]: ReturnType<typeof startHandler>;
[LambdaRoutines.launch]: ReturnType<typeof launchHandler>;
[LambdaRoutines.renderer]: ReturnType<typeof rendererHandler>;
[LambdaRoutines.status]: ReturnType<typeof progressHandler>;
[LambdaRoutines.info]: ReturnType<typeof infoHandler>;
- [LambdaRoutines.still]: OrError<ReturnType<typeof stillHandler>>;
+ [LambdaRoutines.still]: ReturnType<typeof stillHandler>;
[LambdaRoutines.compositions]: ReturnType<typeof compositionsHandler>;
}
diff --git a/packages/renderer/src/browser/BrowserPage.ts b/packages/renderer/src/browser/BrowserPage.ts
index 37664c9e54..343fb27ef6 100644
--- a/packages/renderer/src/browser/BrowserPage.ts
+++ b/packages/renderer/src/browser/BrowserPage.ts
@@ -214,13 +214,31 @@ export class Page extends EventEmitter {
.filter(truthy)
.join(':');
- Log.verboseAdvanced(
- {
- logLevel,
- tag: [origPosition.name, file].filter(truthy).join('@'),
- indent,
- },
- log.previewString
+ const tag = [origPosition?.name, file].filter(truthy).join('@');
+
+ if (log.type === 'error') {
+ Log.errorAdvanced(
+ {
+ logLevel,
+ tag,
+ indent,
+ },
+ log.previewString
+ );
+ } else {
+ Log.verboseAdvanced(
+ {
+ logLevel,
+ tag,
+ indent,
+ },
+ log.previewString
+ );
+ }
+ } else if (log.type === 'error') {
+ Log.errorAdvanced(
+ {logLevel, tag: `console.${log.type}`, indent},
+ log.text
);
} else {
Log.verboseAdvanced(
diff --git a/packages/renderer/src/logger.ts b/packages/renderer/src/logger.ts
index 5a6925d99f..e1b9788669 100644
--- a/packages/renderer/src/logger.ts
+++ b/packages/renderer/src/logger.ts
@@ -75,6 +75,21 @@ export const Log = {
return console.error(...args.map((a) => chalk.red(a)));
}
},
+ errorAdvanced: (
+ options: VerboseLogOptions,
+ ...args: Parameters<typeof console.log>
+ ) => {
+ if (isEqualOrBelowLogLevel(getLogLevel(), 'error')) {
+ return console.log(
+ ...[
+ options.indent ? INDENT_TOKEN : null,
+ options.tag ? verboseTag(options.tag) : null,
+ ]
+ .filter(truthy)
+ .concat(args.map((a) => chalk.red(a)))
+ );
+ }
+ },
};
let logLevel: LogLevel = 'info';