diff --git a/.drone.yml b/.drone.yml index 4f22ab20..d089254c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -14,7 +14,7 @@ steps: - pack - go build -v - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0 - - golangci-lint run --disable errcheck + - golangci-lint run - go test -v -coverprofile=coverage.txt . # - go mod download # - make tools diff --git a/arn/Anime.go b/arn/Anime.go index acd5d007..90b7bc17 100644 --- a/arn/Anime.go +++ b/arn/Anime.go @@ -400,7 +400,7 @@ func (anime *Anime) RefreshEpisodes() error { shoboiEpisodes, err := anime.ShoboiEpisodes() if err != nil { - color.Red(err.Error()) + return err } episodes.Merge(shoboiEpisodes) @@ -409,7 +409,7 @@ func (anime *Anime) RefreshEpisodes() error { twistEpisodes, err := anime.TwistEpisodes() if err != nil { - color.Red(err.Error()) + return err } episodes.Merge(twistEpisodes) @@ -485,7 +485,6 @@ func (anime *Anime) RefreshEpisodes() error { } episodes.Save() - return nil } diff --git a/jobs/jobs.go b/jobs/jobs.go index 80a3f480..866fa860 100644 --- a/jobs/jobs.go +++ b/jobs/jobs.go @@ -41,7 +41,11 @@ func startJobs() { // Log paths logsPath := path.Join(arn.Root, "logs") jobLogsPath := path.Join(arn.Root, "logs", "jobs") - os.Mkdir(jobLogsPath, 0777) + err := os.Mkdir(jobLogsPath, 0777) + + if err != nil { + panic(err) + } // Scheduler log mainLog := log.New() diff --git a/jobs/mal-download/mal-download.go b/jobs/mal-download/mal-download.go index d13eb890..0dc0c5ae 100644 --- a/jobs/mal-download/mal-download.go +++ b/jobs/mal-download/mal-download.go @@ -31,8 +31,17 @@ func main() { defer color.Green("Finished.") // Create directories in case they're missing - os.Mkdir(animeDirectory, 0777) - os.Mkdir(characterDirectory, 0777) + err := os.Mkdir(animeDirectory, 0777) + + if err != nil { + panic(err) + } + + err = os.Mkdir(characterDirectory, 0777) + + if err != nil { + panic(err) + } // Called with arguments? if InvokeShellArgs() { @@ -128,11 +137,15 @@ func queueAnime(anime *arn.Anime, malCrawler *crawler.Crawler) { return } - malCrawler.Queue(&crawler.Task{ + err = malCrawler.Queue(&crawler.Task{ URL: url, Destination: filePath, Raw: true, }) + + if err != nil { + panic(err) + } } func queueCharacter(character *arn.Character, malCrawler *crawler.Crawler) { @@ -146,9 +159,13 @@ func queueCharacter(character *arn.Character, malCrawler *crawler.Crawler) { return } - malCrawler.Queue(&crawler.Task{ + err = malCrawler.Queue(&crawler.Task{ URL: url, Destination: filePath, Raw: true, }) + + if err != nil { + panic(err) + } } diff --git a/jobs/mal-parse/mal-parse.go b/jobs/mal-parse/mal-parse.go index 74ecc750..4119b5c0 100644 --- a/jobs/mal-parse/mal-parse.go +++ b/jobs/mal-parse/mal-parse.go @@ -35,7 +35,7 @@ func main() { func readFiles(root string, onFile func(string) error) { count := 0 - filepath.Walk(root, func(name string, info os.FileInfo, err error) error { + err := filepath.Walk(root, func(name string, info os.FileInfo, err error) error { if err != nil { color.Red(err.Error()) return err @@ -61,6 +61,10 @@ func readFiles(root string, onFile func(string) error) { return nil }) + if err != nil { + panic(err) + } + // Erase line print("\r\033[2K") diff --git a/jobs/mal-parse/shell.go b/jobs/mal-parse/shell.go index d89c960f..3e7f0a42 100644 --- a/jobs/mal-parse/shell.go +++ b/jobs/mal-parse/shell.go @@ -30,7 +30,11 @@ func InvokeShellArgs() bool { panic("No MAL ID") } - readAnimeFile(path.Join(arn.Root, "jobs", "mal-download", "anime", anime.GetMapping("myanimelist/anime")+".html.gz")) + err = readAnimeFile(path.Join(arn.Root, "jobs", "mal-download", "anime", anime.GetMapping("myanimelist/anime")+".html.gz")) + + if err != nil { + panic(err) + } case "character": character, err := arn.GetCharacter(objectID) @@ -40,7 +44,11 @@ func InvokeShellArgs() bool { panic("No MAL ID") } - readCharacterFile(path.Join(arn.Root, "jobs", "mal-download", "character", character.GetMapping("myanimelist/character")+".html.gz")) + err = readCharacterFile(path.Join(arn.Root, "jobs", "mal-download", "character", character.GetMapping("myanimelist/character")+".html.gz")) + + if err != nil { + panic(err) + } } return true diff --git a/jobs/twist/twist.go b/jobs/twist/twist.go index e6544f6e..87ac4124 100644 --- a/jobs/twist/twist.go +++ b/jobs/twist/twist.go @@ -46,7 +46,12 @@ func main() { } // Refresh - anime.RefreshEpisodes() + err := anime.RefreshEpisodes() + + if err != nil { + color.Red(err.Error()) + continue + } // Ok color.Green("Found %d episodes for anime %s (Kitsu: %s)", len(anime.Episodes().Items), anime.ID, kitsuID) diff --git a/pages/editor/jobs/start.go b/pages/editor/jobs/start.go index fc80861d..64e9c6eb 100644 --- a/pages/editor/jobs/start.go +++ b/pages/editor/jobs/start.go @@ -35,7 +35,12 @@ func Start(ctx aero.Context) error { return ctx.Error(http.StatusBadRequest, "Job is currently running!") } - job.Start() + err := job.Start() + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Job could not be started!", err) + } + jobLogs = append(jobLogs, user.Nick+" started "+job.Name+" job ("+arn.DateTimeUTC()+").") return nil diff --git a/pages/shop/buyitem.go b/pages/shop/buyitem.go index 7c90e956..f484baa6 100644 --- a/pages/shop/buyitem.go +++ b/pages/shop/buyitem.go @@ -45,14 +45,20 @@ func BuyItem(ctx aero.Context) error { return ctx.Error(http.StatusBadRequest, "Not enough gems. You need to charge up your balance before you can buy this item.") } - user.Balance -= totalPrice - user.Save() - // Add item to user inventory inventory := user.Inventory() - inventory.AddItem(itemID, uint(quantity)) + err = inventory.AddItem(itemID, uint(quantity)) + + if err != nil { + return ctx.Error(http.StatusBadRequest, err) + } + inventory.Save() + // Deduct balance + user.Balance -= totalPrice + user.Save() + // Save purchase purchase := arn.NewPurchase(user.ID, itemID, quantity, int(item.Price), "gem") purchase.Save() diff --git a/pages/soundtrack/download.go b/pages/soundtrack/download.go index 617b4e20..2858764d 100644 --- a/pages/soundtrack/download.go +++ b/pages/soundtrack/download.go @@ -23,6 +23,5 @@ func Download(ctx aero.Context) error { return ctx.Error(http.StatusNotFound, "Track not found", err) } - track.Download() - return nil + return track.Download() } diff --git a/patches/add-item/add-item.go b/patches/add-item/add-item.go index 3a2f43bb..ac1b5fea 100644 --- a/patches/add-item/add-item.go +++ b/patches/add-item/add-item.go @@ -3,6 +3,7 @@ package main import ( "flag" + "github.com/akyoto/color" "github.com/animenotifier/notify.moe/arn" ) @@ -33,17 +34,28 @@ func main() { // Single user user, err := arn.GetUserByNick(nick) arn.PanicOnError(err) - addItemToUser(user) + err = addItemToUser(user) + arn.PanicOnError(err) } else { // All users for user := range arn.StreamUsers() { - addItemToUser(user) + err = addItemToUser(user) + + if err != nil { + color.Red(err.Error()) + } } } } -func addItemToUser(user *arn.User) { +func addItemToUser(user *arn.User) error { inventory := user.Inventory() - inventory.AddItem(itemID, uint(quantity)) + err := inventory.AddItem(itemID, uint(quantity)) + + if err != nil { + return err + } + inventory.Save() + return nil } diff --git a/patches/kitsu-download-anime-images/kitsu-download-anime-images.go b/patches/kitsu-download-anime-images/kitsu-download-anime-images.go index 26d27d15..516a8209 100644 --- a/patches/kitsu-download-anime-images/kitsu-download-anime-images.go +++ b/patches/kitsu-download-anime-images/kitsu-download-anime-images.go @@ -47,7 +47,11 @@ func main() { for index, anime := range allAnime { fmt.Printf("%d / %d\n", index+1, len(allAnime)) - work(anime) + err := work(anime) + + if err != nil { + color.Red(err.Error()) + } } // Give file buffers some time, just to be safe @@ -63,16 +67,18 @@ func work(anime *arn.Anime) error { response, err := client.Get(kitsuOriginal).End() if err != nil { - color.Red("%s (%s)", err.Error(), kitsuOriginal) - return err + return fmt.Errorf("%s (%s)", err.Error(), kitsuOriginal) } if response.StatusCode() != http.StatusOK { - color.Red("Status %d (%s)", response.StatusCode(), kitsuOriginal) - return err + return fmt.Errorf("Status %d (%s)", response.StatusCode(), kitsuOriginal) } - anime.SetImageBytes(response.Bytes()) + err = anime.SetImageBytes(response.Bytes()) + + if err != nil { + return err + } // Try to free up some memory runtime.GC() diff --git a/patches/optimize-all-webm-files/optimize-all-webm-files.go b/patches/optimize-all-webm-files/optimize-all-webm-files.go index a76626ab..9a945e35 100644 --- a/patches/optimize-all-webm-files/optimize-all-webm-files.go +++ b/patches/optimize-all-webm-files/optimize-all-webm-files.go @@ -64,7 +64,7 @@ func mkclean(file string) error { // Read files in a given directory and apply a function on them func readFiles(root string, onFile func(string) error) { - filepath.Walk(root, func(name string, info os.FileInfo, err error) error { + err := filepath.Walk(root, func(name string, info os.FileInfo, err error) error { if err != nil { color.Red(err.Error()) return err @@ -87,4 +87,8 @@ func readFiles(root string, onFile func(string) error) { // Always continue traversing the directory return nil }) + + if err != nil { + color.Red(err.Error()) + } } diff --git a/patches/remove-character-borders/remove-character-borders.go b/patches/remove-character-borders/remove-character-borders.go index 5393b859..26ce75e6 100644 --- a/patches/remove-character-borders/remove-character-borders.go +++ b/patches/remove-character-borders/remove-character-borders.go @@ -62,7 +62,13 @@ func process(character *arn.Character) { return } - character.SetImageBytes(buffer.Bytes()) + err = character.SetImageBytes(buffer.Bytes()) + + if err != nil { + color.Red(err.Error()) + return + } + character.Save() } diff --git a/patches/user-references/user-references.go b/patches/user-references/user-references.go index bfa6c5bd..34724554 100644 --- a/patches/user-references/user-references.go +++ b/patches/user-references/user-references.go @@ -33,7 +33,11 @@ func main() { user.ForceSetNick(user.Nick) if user.Email != "" { - user.SetEmail(user.Email) + err := user.SetEmail(user.Email) + + if err != nil { + color.Red(err.Error()) + } } if user.Accounts.Google.ID != "" {