Skip to content

🎥 Make videos programmatically with React

improving error message for timeout

Jonny Burgerad51f97309bb
diff --git a/packages/lambda/src/functions/helpers/make-timeout-error.ts b/packages/lambda/src/functions/helpers/make-timeout-error.ts
index 05e67405a2..25ef97a4a9 100644
--- a/packages/lambda/src/functions/helpers/make-timeout-error.ts
+++ b/packages/lambda/src/functions/helpers/make-timeout-error.ts
@@ -1,7 +1,7 @@
import type {_Object} from '@aws-sdk/client-s3';
import type {RenderMetadata} from '../../defaults';
-import {DOCS_URL} from '../../shared/docs-url';
import {parseLambdaChunkKey} from '../../shared/parse-chunk-key';
+import {makeTimeoutMessage} from './make-timeout-message';
import type {EnhancedErrorInfo} from './write-lambda-error';
export const makeTimeoutError = ({
@@ -24,26 +24,11 @@ export const makeTimeoutError = ({
})
.map((_, i) => i);
- const missingChunksMessageList = missingChunks
- .map((ch) => {
- const isLastChunk = ch === renderMetadata.totalChunks - 1;
- const start = ch * renderMetadata.framesPerLambda;
- const end = isLastChunk
- ? renderMetadata.frameRange[1]
- : (ch + 1) * renderMetadata.framesPerLambda - 1;
-
- return `Chunk ${ch} (Frames ${start} - ${end})`;
- })
- .slice(0, 5)
- .join(', ');
-
- const message = [
- `The main function timed out after ${timeoutInMilliseconds}ms.`,
- `Consider increasing the timeout of your function.`,
- `The following chunks are missing (showing up to 5): ${missingChunksMessageList}.`,
- `You can use the "--timeout" parameter when deploying a function via CLI, or the "timeoutInSeconds" parameter when using the deployFunction() API.`,
- `${DOCS_URL}/docs/lambda/cli/functions#deploy`,
- ].join('\n');
+ const message = makeTimeoutMessage({
+ missingChunks,
+ renderMetadata,
+ timeoutInMilliseconds,
+ });
return {
attempt: 1,
diff --git a/packages/lambda/src/functions/helpers/make-timeout-message.ts b/packages/lambda/src/functions/helpers/make-timeout-message.ts
new file mode 100644
index 0000000000..02d9a2e658
--- /dev/null
+++ b/packages/lambda/src/functions/helpers/make-timeout-message.ts
@@ -0,0 +1,50 @@
+import type {RenderMetadata} from '../../defaults';
+import {DOCS_URL} from '../../shared/docs-url';
+
+const makeChunkMissingMessage = ({
+ missingChunks,
+ renderMetadata,
+}: {
+ missingChunks: number[];
+ renderMetadata: RenderMetadata;
+}) => {
+ const missingChunksMessageList = missingChunks
+ .map((ch) => {
+ const isLastChunk = ch === renderMetadata.totalChunks - 1;
+ const start = ch * renderMetadata.framesPerLambda;
+ const end = isLastChunk
+ ? renderMetadata.frameRange[1]
+ : (ch + 1) * renderMetadata.framesPerLambda - 1;
+
+ return `Chunk ${ch} (Frames ${start} - ${end})`;
+ })
+ .slice(0, 5);
+
+ if (missingChunksMessageList.length === 0) {
+ return 'All chunks have been successfully rendered, but the main function has timed out.';
+ }
+
+ return `The following chunks are missing (showing ${
+ missingChunksMessageList.length
+ } out of ${missingChunks.length}): ${missingChunksMessageList.join(', ')}.`;
+};
+
+export const makeTimeoutMessage = ({
+ timeoutInMilliseconds,
+ missingChunks,
+ renderMetadata,
+}: {
+ timeoutInMilliseconds: number;
+ missingChunks: number[];
+ renderMetadata: RenderMetadata;
+}) => {
+ const message = [
+ `The main function timed out after ${timeoutInMilliseconds}ms.`,
+ `Consider increasing the timeout of your function.`,
+ makeChunkMissingMessage({missingChunks, renderMetadata}),
+ `You can use the "--timeout" parameter when deploying a function via CLI, or the "timeoutInSeconds" parameter when using the deployFunction() API.`,
+ `${DOCS_URL}/docs/lambda/cli/functions#deploy`,
+ ].join('\n');
+
+ return message;
+};