Skip to content

Commit

Permalink
Reworked error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigal committed May 5, 2024
1 parent e3395f7 commit c88ac8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
34 changes: 6 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -154,11 +155,7 @@ func startProcessing() {
g.Update()

if anime.HasSubtitlesStream && outputFormat != "mkv" {
animeList[index].Status = Error
gui.ButtonLabel = "Start"
processing = false
logMessage("File "+anime.Name+" contains subtitles stream, output format must be MKV", false)
g.Update()
handleStartUpscalingError("", index, "File "+anime.Name+" contains subtitles stream, output format must be MKV", errors.New(""))
return
}

Expand All @@ -167,11 +164,7 @@ func startProcessing() {

workingDirectory, err := os.Getwd()
if err != nil {
animeList[index].Status = Error
gui.ButtonLabel = "Start"
processing = false
g.Update()
handleSoftError("Getting working directory error:", err.Error())
handleStartUpscalingError("", index, "Getting working directory error:", err)
return
}

Expand All @@ -189,41 +182,26 @@ func startProcessing() {

stderr, err := cmd.StderrPipe()
if err != nil {
os.Remove(outputPath)
animeList[index].Status = Error
gui.ButtonLabel = "Start"
processing = false
g.Update()
handleSoftError("Creating pipe error:", err.Error())
handleStartUpscalingError(outputPath, index, "Creating pipe error:", err)
return
}

err = cmd.Start()
if err != nil {
os.Remove(outputPath)
animeList[index].Status = Error
gui.ButtonLabel = "Start"
processing = false
g.Update()
handleSoftError("Starting ffmpeg process error:", err.Error())
handleStartUpscalingError(outputPath, index, "Starting ffmpeg process error:", err)
return
}

ffmpegLogs := handleUpscalingLogs(stderr, anime)

err = cmd.Wait()
if err != nil {
os.Remove(outputPath)
if cancelled {
cancelled = false
return
}

animeList[index].Status = Error
gui.ButtonLabel = "Start"
processing = false
g.Update()
handleSoftError("FFMPEG Error:", err.Error())
handleStartUpscalingError(outputPath, index, "FFMPEG Error:", err)
handleSoftError("FFMPEG logs:", ffmpegLogs)
return
}
Expand Down
18 changes: 18 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,21 @@ func check(err error) {
log.Fatal(err)
}
}

func handleStartUpscalingError(outputPath string, animeIndex int, errorMessage string, err error) {
if outputPath != "" {
os.Remove(outputPath)
}

animeList[animeIndex].Status = Error
gui.ButtonLabel = "Start"
processing = false
g.Update()

if err.Error() != "" {
handleSoftError(errorMessage, err.Error())
return
}

logMessage("File "+animeList[animeIndex].Name+" contains subtitles stream, output format must be MKV", false)
}

0 comments on commit c88ac8f

Please sign in to comment.