Fixed errcheck linter complaints
This commit is contained in:
parent
190a85fe08
commit
940e949a30
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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 != "" {
|
||||
|
Loading…
Reference in New Issue
Block a user