From 910cbec8e1007c38be2cdf5963863d338389b121 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 16 Jan 2026 03:45:57 +0000 Subject: [PATCH] Fix production bugs: missing binary error handling and file race conditions - Added error listeners to `spawn` calls in `src/main/main.js` to catch and report missing `yt-dlp` binaries gracefully instead of crashing or hanging. - Updated `src/main/downloader.js` to refresh the file list immediately after download completion, fixing a race condition where the `postProcess` method failed to find the downloaded file. - Corrected `sanitizeFilename` regex in `src/main/main.js` to properly preserve spaces while stripping illegal characters. - Verified platform-specific binary resolution logic for Windows and Linux. --- src/main/downloader.js | 12 ++++++++---- src/main/main.js | Bin 18313 -> 18707 bytes 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/downloader.js b/src/main/downloader.js index d0de873..5d30987 100644 --- a/src/main/downloader.js +++ b/src/main/downloader.js @@ -339,7 +339,11 @@ ${stderrOutput}`; const info = JSON.parse(infoData); await fs.promises.unlink(infoJsonPath); const realId = info.id; - const mediaFile = files.find( + + // Refresh file list to catch any file operations that completed in the meantime + const currentFiles = await fs.promises.readdir(this.videoPath); + + const mediaFile = currentFiles.find( (f) => (f.startsWith(videoInfo.id) || f.startsWith(realId)) && !f.endsWith('.json') && @@ -351,7 +355,7 @@ ${stderrOutput}`; if (!mediaFile) throw new Error('Media file not found after download.'); const mediaFilePath = path.join(this.videoPath, mediaFile); let finalCoverPath = null; - const thumbFile = files.find( + const thumbFile = currentFiles.find( (f) => (f.startsWith(videoInfo.id) || f.startsWith(realId)) && (f.endsWith('.jpg') || f.endsWith('.webp')) @@ -366,7 +370,7 @@ ${stderrOutput}`; ? url.pathToFileURL(finalCoverPath).href : null; let subFileUri = null; - const subFile = files.find( + const subFile = currentFiles.find( (f) => f.startsWith(videoInfo.id) && f.endsWith('.vtt') ); if (subFile) { @@ -376,7 +380,7 @@ ${stderrOutput}`; }); subFileUri = url.pathToFileURL(destSub).href; } - const descFile = files.find( + const descFile = currentFiles.find( (f) => f.startsWith(videoInfo.id) && f.endsWith('.description') ); if (descFile) diff --git a/src/main/main.js b/src/main/main.js index 558537cd2ca7874182bd8a33c140007f5ff523f1..4ffc04bbbf1990cb0b6ba45f3203deb4df4c06f0 100644 GIT binary patch delta 359 zcmeC|XPi8VaYM7v=2=1pqEe|vMfpYQItm)a1&QT(t{|SKf~}oGHP_?-0TF4CpaNLb z3aAK4jWyTgMr+~8>AYf-XKQj!?$HvTyj+XF9&DVILV{ajW=?8~LP@?taYL6CQ&DQMMm5koDfy)(RtoCsV2fdr5T}56wVIm`7@QOX0Aa9h&j0`b delta 39 vcmbO{iLtYvaYM5ZpI%XFK~7?Fs)l|vgRcDMDj`eJ&DS-)aBTK4IxPkO5dRJ2