Skip to content

Commit 0b39057

Browse files
ntsklabCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent f901f65 commit 0b39057

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/media.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ export function calculateThumbnailSize(
8080
export async function makeVideoScreenshot(
8181
videoData: Uint8Array,
8282
): Promise<Uint8Array> {
83-
const tmpDir = await mkdtemp(join(tmpdir(), "hollo-"));
84-
const inFile = join(tmpDir, "video");
83+
let tmpDir: string | undefined;
8584
try {
85+
tmpDir = await mkdtemp(join(tmpdir(), "hollo-"));
86+
const inFile = join(tmpDir, "video");
8687
await writeFile(inFile, videoData);
8788
const resultBuffer: Buffer = await new Promise((resolve) => {
8889
const process = spawn("ffmpeg", [
@@ -140,12 +141,14 @@ export async function makeVideoScreenshot(
140141
});
141142
return defaultScreenshot;
142143
} finally {
143-
try {
144-
await rm(tmpDir, { recursive: true, force: true });
145-
} catch (cleanupError) {
146-
logger.warn("Failed to clean up temporary directory: {error}", {
147-
error: cleanupError,
148-
});
144+
if (tmpDir) {
145+
try {
146+
await rm(tmpDir, { recursive: true, force: true });
147+
} catch (cleanupError) {
148+
logger.warn("Failed to clean up temporary directory: {error}", {
149+
error: cleanupError,
150+
});
151+
}
149152
}
150153
}
151154
}

0 commit comments

Comments
 (0)