mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 15:04:32 +02:00
Fix unhandled error warnings, error messages (except import.go)
This commit is contained in:
@@ -21,5 +21,5 @@ func getCurseDir() (string, error) {
|
||||
if _, err := os.Stat(curseDir); err == nil {
|
||||
return curseDir, nil
|
||||
}
|
||||
return "", errors.New("Curse installation directory cannot be found")
|
||||
return "", errors.New("curse installation directory cannot be found")
|
||||
}
|
||||
|
@@ -33,6 +33,9 @@ func getFileIDsFromString(mod string) (bool, int, int, error) {
|
||||
matches := v.FindStringSubmatch(mod)
|
||||
if matches != nil && len(matches) == 3 {
|
||||
modID, err := modIDFromSlug(matches[1])
|
||||
if err != nil {
|
||||
return true, 0, 0, err
|
||||
}
|
||||
fileID, err := strconv.Atoi(matches[2])
|
||||
if err != nil {
|
||||
return true, 0, 0, err
|
||||
|
@@ -45,9 +45,7 @@ var exportCmd = &cobra.Command{
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer expFile.Close()
|
||||
exp := zip.NewWriter(expFile)
|
||||
defer exp.Close()
|
||||
|
||||
cfFileRefs := make([]packinterop.AddonFileReference, 0, len(mods))
|
||||
for _, mod := range mods {
|
||||
@@ -82,18 +80,24 @@ var exportCmd = &cobra.Command{
|
||||
|
||||
manifestFile, err := exp.Create("manifest.json")
|
||||
if err != nil {
|
||||
_ = exp.Close()
|
||||
_ = expFile.Close()
|
||||
fmt.Println("Error creating manifest: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = packinterop.WriteManifestFromPack(pack, cfFileRefs, manifestFile)
|
||||
if err != nil {
|
||||
_ = exp.Close()
|
||||
_ = expFile.Close()
|
||||
fmt.Println("Error creating manifest: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = createModlist(exp, mods)
|
||||
if err != nil {
|
||||
_ = exp.Close()
|
||||
_ = expFile.Close()
|
||||
fmt.Println("Error creating mod list: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -124,6 +128,17 @@ var exportCmd = &cobra.Command{
|
||||
}
|
||||
}
|
||||
|
||||
err = exp.Close()
|
||||
if err != nil {
|
||||
fmt.Println("Error writing export file: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
err = expFile.Close()
|
||||
if err != nil {
|
||||
fmt.Println("Error writing export file: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("Modpack exported to export.zip!")
|
||||
},
|
||||
}
|
||||
|
@@ -79,22 +79,24 @@ func modIDFromSlug(slug string) (int, error) {
|
||||
}
|
||||
|
||||
if len(response.Exception) > 0 || len(response.Message) > 0 {
|
||||
return 0, fmt.Errorf("Error requesting id for slug: %s", response.Message)
|
||||
return 0, fmt.Errorf("error requesting id for slug: %s", response.Message)
|
||||
}
|
||||
|
||||
if len(response.Data.Addons) < 1 {
|
||||
return 0, errors.New("Addon not found")
|
||||
return 0, errors.New("addon not found")
|
||||
}
|
||||
|
||||
return response.Data.Addons[0].ID, nil
|
||||
}
|
||||
|
||||
//noinspection GoUnusedConst
|
||||
const (
|
||||
fileTypeRelease int = iota + 1
|
||||
fileTypeBeta
|
||||
fileTypeAlpha
|
||||
)
|
||||
|
||||
//noinspection GoUnusedConst
|
||||
const (
|
||||
dependencyTypeEmbedded int = iota + 1
|
||||
dependencyTypeOptional
|
||||
@@ -146,7 +148,7 @@ func getModInfo(modID int) (modInfo, error) {
|
||||
}
|
||||
|
||||
if infoRes.ID != modID {
|
||||
return modInfo{}, fmt.Errorf("Unexpected addon ID in CurseForge response: %d/%d", modID, infoRes.ID)
|
||||
return modInfo{}, fmt.Errorf("unexpected addon ID in CurseForge response: %d/%d", modID, infoRes.ID)
|
||||
}
|
||||
|
||||
return infoRes, nil
|
||||
@@ -250,7 +252,7 @@ func getFileInfo(modID int, fileID int) (modFileInfo, error) {
|
||||
}
|
||||
|
||||
if infoRes.ID != fileID {
|
||||
return modFileInfo{}, fmt.Errorf("Unexpected file ID in CurseForge response: %d/%d", modID, infoRes.ID)
|
||||
return modFileInfo{}, fmt.Errorf("unexpected file ID in CurseForge response: %d/%d", modID, infoRes.ID)
|
||||
}
|
||||
|
||||
return infoRes, nil
|
||||
|
Reference in New Issue
Block a user