From a823c345df9be5e9590c7bac3543a2ceb1a03d1d Mon Sep 17 00:00:00 2001 From: an-lee Date: Tue, 16 Jan 2024 23:32:49 +0800 Subject: [PATCH] Fix: logs and notify more friendly (#127) * popup the error when whisper/ffmpeg failed * fix ffmpeg error handler --- .../db/handlers/transcriptions-handler.ts | 8 ++++++-- enjoy/src/main/ffmpeg.ts | 20 +++++++++++++------ enjoy/src/main/whisper.ts | 5 ++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/enjoy/src/main/db/handlers/transcriptions-handler.ts b/enjoy/src/main/db/handlers/transcriptions-handler.ts index b04ee48e..31e63dab 100644 --- a/enjoy/src/main/db/handlers/transcriptions-handler.ts +++ b/enjoy/src/main/db/handlers/transcriptions-handler.ts @@ -30,12 +30,16 @@ class TranscriptionsHandler { }); if (transcription.state === "pending") { - transcription.process(); + transcription.process().catch((err) => { + event.sender.send("on-notification", { + type: "error", + message: err.message, + }); + }); } return transcription.toJSON(); } catch (err) { - logger.error(err); event.sender.send("on-notification", { type: "error", message: err.message, diff --git a/enjoy/src/main/ffmpeg.ts b/enjoy/src/main/ffmpeg.ts index 63ba2433..484031cc 100644 --- a/enjoy/src/main/ffmpeg.ts +++ b/enjoy/src/main/ffmpeg.ts @@ -139,14 +139,24 @@ export default class FfmpegWrapper { ...options ) .on("start", (commandLine) => { + logger.debug(`Trying to convert ${input} to ${output}`); logger.info("Spawned FFmpeg with command: " + commandLine); fs.ensureDirSync(path.dirname(output)); }) - .on("end", (_stdout, stderr) => { + .on("end", (stdout, stderr) => { + if (stdout) { + logger.debug(stdout); + } + if (stderr) { logger.error(stderr); } - resolve(output); + + if (fs.existsSync(output)) { + resolve(output); + } else { + reject(new Error("FFmpeg command failed")); + } }) .on("error", (err: Error) => { logger.error(err); @@ -171,11 +181,9 @@ export default class FfmpegWrapper { } } - logger.info( - `[WHISPER] Trying to convert ${input} to 16-bit WAVE file ${output}` - ); + logger.info(`Trying to convert ${input} to 16-bit WAVE file ${output}`); if (fs.pathExistsSync(output)) { - logger.warn(`[WHISPER] File ${output} already exists, deleting.`); + logger.warn(`File ${output} already exists, deleting.`); fs.removeSync(output); } diff --git a/enjoy/src/main/whisper.ts b/enjoy/src/main/whisper.ts index b6dd820b..81d8bc35 100644 --- a/enjoy/src/main/whisper.ts +++ b/enjoy/src/main/whisper.ts @@ -105,7 +105,10 @@ class Whipser { logger.debug(stdout); } - reject(new Error("Whisper transcribe failed: unknown error")); + reject( + error || + new Error(stderr || "Whisper transcribe failed: unknown error") + ); } ); });