🎥 Make videos programmatically with React
better error handling when opening file
Jonny Burger6623c55c647d
diff --git a/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx b/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsxindex ab94547f68..84b6ae9f32 100644--- a/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx+++ b/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx@@ -1,9 +1,6 @@import React, {useCallback} from 'react';-import type {- OpenInFileExplorerRequest,- RenderJob,-} from '../../../preview-server/render-queue/job';-import {notificationCenter} from '../Notifications/NotificationCenter';+import type {RenderJob} from '../../../preview-server/render-queue/job';+import {openInFileExplorer} from './actions';import {renderQueueItemSubtitleStyle} from './item-style';const outputLocation: React.CSSProperties = {@@ -28,37 +25,7 @@ export const RenderQueueOutputName: React.FC<{job: RenderJob;}> = ({job}) => {const onClick = useCallback(() => {- const body: OpenInFileExplorerRequest = {- directory: job.outputLocation,- };- fetch(`/api/open-in-file-explorer`, {- method: 'post',- headers: {- 'content-type': 'application/json',- },- body: JSON.stringify(body),- })- .then((res) => res.json())- .then((data: {success: true} | {success: false; error: string}) => {- if (data.success) {- console.log('Opened file in explorer');- } else {- notificationCenter.current?.addNotification({- content: `Could not open file: ${data.error}`,- created: Date.now(),- duration: 2000,- id: String(Math.random()),- });- }- })- .catch((err) => {- notificationCenter.current?.addNotification({- content: `Could not open file: ${err.message}`,- created: Date.now(),- duration: 2000,- id: String(Math.random()),- });- });+ openInFileExplorer({directory: job.outputLocation});}, [job.outputLocation]);return (diff --git a/packages/cli/src/editor/components/RenderQueue/actions.ts b/packages/cli/src/editor/components/RenderQueue/actions.tsindex 06168aa5ab..f7851cd78c 100644--- a/packages/cli/src/editor/components/RenderQueue/actions.ts+++ b/packages/cli/src/editor/components/RenderQueue/actions.ts@@ -2,9 +2,11 @@ import type {StillImageFormat} from '@remotion/renderer';import type {TCompMetadata} from 'remotion';import type {AddRenderRequest,+ OpenInFileExplorerRequest,RemoveRenderRequest,RenderJob,} from '../../../preview-server/render-queue/job';+import {notificationCenter} from '../Notifications/NotificationCenter';export const removeRenderJob = (job: RenderJob) => {const body: RemoveRenderRequest = {@@ -81,3 +83,37 @@ export const addStillRenderJob = ({});});};++export const openInFileExplorer = ({directory}: {directory: string}) => {+ const body: OpenInFileExplorerRequest = {+ directory,+ };+ fetch(`/api/open-in-file-explorer`, {+ method: 'post',+ headers: {+ 'content-type': 'application/json',+ },+ body: JSON.stringify(body),+ })+ .then((res) => res.json())+ .then((data: {success: true} | {success: false; error: string}) => {+ if (data.success) {+ console.log('Opened file in explorer');+ } else {+ notificationCenter.current?.addNotification({+ content: `Could not open file: ${data.error}`,+ created: Date.now(),+ duration: 2000,+ id: String(Math.random()),+ });+ }+ })+ .catch((err) => {+ notificationCenter.current?.addNotification({+ content: `Could not open file: ${err.message}`,+ created: Date.now(),+ duration: 2000,+ id: String(Math.random()),+ });+ });+};diff --git a/packages/cli/src/preview-server/render-queue/open-directory-in-finder.ts b/packages/cli/src/preview-server/render-queue/open-directory-in-finder.tsindex 663246b6a9..a2d59301df 100644--- a/packages/cli/src/preview-server/render-queue/open-directory-in-finder.ts+++ b/packages/cli/src/preview-server/render-queue/open-directory-in-finder.ts@@ -14,12 +14,16 @@ export const openDirectoryInFinder = (dirToOpen: string) => {// TODO: '-R' only works on macOSconst p = spawn(command, ['-R', dirToOpen]);+ const stderrChunks: Buffer[] = [];+ p.stderr.on('data', (d) => stderrChunks.push(d));+return new Promise<void>((resolve, reject) => {p.on('exit', (code) => {if (code === 0) {resolve();} else {- reject(new Error(`Exited with code ${code}`));+ const message = Buffer.concat(stderrChunks).toString('utf-8');+ reject(new Error(message));}});p.on('error', (err) => {diff --git a/packages/cli/src/preview-server/render-queue/queue.ts b/packages/cli/src/preview-server/render-queue/queue.tsindex 542e9b3e1d..85f5026439 100644--- a/packages/cli/src/preview-server/render-queue/queue.ts+++ b/packages/cli/src/preview-server/render-queue/queue.ts@@ -122,6 +122,7 @@ export const processJob = async ({quality: job.quality ?? undefined,imageFormat: job.imageFormat,frame: job.frame,+// TODO: Allow cancel signal// TODO: Accept CLI options});