Skip to content

Commit

Permalink
More logging, less error nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Dec 30, 2023
1 parent 189faa4 commit 0949c5f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
10 changes: 5 additions & 5 deletions backend/bindings/ficsitcli/installs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (f *FicsitCLI) GetInvalidInstalls() []string {
result := []string{}
for _, err := range f.installFindErrors {
var installFindErr common.InstallFindError
if ok := errors.As(err, &installFindErr); ok {
if errors.As(err, &installFindErr) {
result = append(result, installFindErr.Path)
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (f *FicsitCLI) SelectInstall(path string) error {

if installErr != nil {
l.Error("failed to validate install", slog.Any("error", installErr))
return errors.Wrap(installErr, "Failed to validate install")
return installErr
}
return nil
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func (f *FicsitCLI) SetModsEnabled(enabled bool) error {

if installErr != nil {
l.Error("failed to validate install", slog.Any("error", installErr))
return errors.Wrap(installErr, "failed to validate install")
return installErr
}

return nil
Expand All @@ -248,7 +248,7 @@ func (f *FicsitCLI) GetSelectedInstallLockfileMods() (map[string]resolver.Locked
}
lockfile, err := f.selectedInstallation.Installation.LockFile(f.ficsitCli)
if err != nil {
return nil, errors.Wrap(err, "failed to get lockfile")
return nil, err //nolint:wrapcheck
}
if lockfile == nil {
return make(map[string]resolver.LockedMod), nil
Expand All @@ -262,7 +262,7 @@ func (f *FicsitCLI) GetSelectedInstallLockfile() (*resolver.LockFile, error) {
}
lockfile, err := f.selectedInstallation.Installation.LockFile(f.ficsitCli)
if err != nil {
return nil, errors.Wrap(err, "failed to get lockfile")
return nil, err //nolint:wrapcheck
}
return lockfile, nil
}
Expand Down
36 changes: 29 additions & 7 deletions backend/bindings/ficsitcli/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/puzpuzpuz/xsync/v3"
"github.com/satisfactorymodding/ficsit-cli/cli"
ficsitUtils "github.com/satisfactorymodding/ficsit-cli/utils"
resolver "github.com/satisfactorymodding/ficsit-resolver"
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"

"github.com/satisfactorymodding/SatisfactoryModManager/backend/utils"
Expand Down Expand Up @@ -154,7 +155,11 @@ func (f *FicsitCLI) validateInstall(installation *InstallationInfo, progressItem

installErr := installation.Installation.Install(f.ficsitCli, installChannel)
if installErr != nil {
return errors.Wrap(installErr, "failed to install")
var solvingError resolver.DependencyResolverError
if errors.As(installErr, &solvingError) {
return solvingError
}
return installErr //nolint:wrapcheck
}
return nil
}
Expand Down Expand Up @@ -202,11 +207,14 @@ func (f *FicsitCLI) InstallMod(mod string) error {
return errors.New("no installation selected")
}

l := slog.With(slog.String("task", "installMod"), slog.String("mod", mod), utils.SlogPath("install", f.selectedInstallation.Info.Path))

profileName := f.selectedInstallation.Installation.Profile
profile := f.GetProfile(profileName)

profileErr := profile.AddMod(mod, ">=0.0.0")
if profileErr != nil {
l.Error("failed to add mod", slog.Any("error", profileErr))
return errors.Wrapf(profileErr, "failed to add mod: %s@latest", mod)
}

Expand All @@ -223,7 +231,8 @@ func (f *FicsitCLI) InstallMod(mod string) error {
installErr := f.validateInstall(f.selectedInstallation, mod)

if installErr != nil {
return errors.Wrapf(installErr, "failed to install mod: %s@latest", mod)
l.Error("failed to install", slog.Any("error", installErr))
return installErr
}

_ = f.ficsitCli.Profiles.Save()
Expand All @@ -240,12 +249,15 @@ func (f *FicsitCLI) InstallModVersion(mod string, version string) error {
return errors.New("no installation selected")
}

l := slog.With(slog.String("task", "installModVersion"), slog.String("mod", mod), slog.String("version", version), utils.SlogPath("install", f.selectedInstallation.Info.Path))

profileName := f.selectedInstallation.Installation.Profile
profile := f.GetProfile(profileName)

profileErr := profile.AddMod(mod, version)
if profileErr != nil {
return errors.Wrapf(profileErr, "Failed to add mod: %s@%s", mod, version)
l.Error("failed to add mod", slog.Any("error", profileErr))
return errors.Wrapf(profileErr, "failed to add mod: %s@%s", mod, version)
}

f.progress = &Progress{
Expand All @@ -261,7 +273,8 @@ func (f *FicsitCLI) InstallModVersion(mod string, version string) error {
installErr := f.validateInstall(f.selectedInstallation, mod)

if installErr != nil {
return errors.Wrapf(installErr, "failed to install mod: %s@%s", mod, version)
l.Error("failed to install", slog.Any("error", installErr))
return installErr
}

_ = f.ficsitCli.Profiles.Save()
Expand All @@ -278,6 +291,8 @@ func (f *FicsitCLI) RemoveMod(mod string) error {
return errors.New("no installation selected")
}

l := slog.With(slog.String("task", "removeMod"), slog.String("mod", mod), utils.SlogPath("install", f.selectedInstallation.Info.Path))

profileName := f.selectedInstallation.Installation.Profile
profile := f.GetProfile(profileName)

Expand All @@ -296,7 +311,8 @@ func (f *FicsitCLI) RemoveMod(mod string) error {
installErr := f.validateInstall(f.selectedInstallation, mod)

if installErr != nil {
return errors.Wrapf(installErr, "failed to remove mod: %s", mod)
l.Error("failed to install", slog.Any("error", installErr))
return installErr
}

_ = f.ficsitCli.Profiles.Save()
Expand All @@ -313,6 +329,8 @@ func (f *FicsitCLI) EnableMod(mod string) error {
return errors.New("no installation selected")
}

l := slog.With(slog.String("task", "enableMod"), slog.String("mod", mod), utils.SlogPath("install", f.selectedInstallation.Info.Path))

profileName := f.selectedInstallation.Installation.Profile
profile := f.GetProfile(profileName)

Expand All @@ -331,7 +349,8 @@ func (f *FicsitCLI) EnableMod(mod string) error {
installErr := f.validateInstall(f.selectedInstallation, mod)

if installErr != nil {
return errors.Wrapf(installErr, "failed to enable mod: %s", mod)
l.Error("failed to install", slog.Any("error", installErr))
return installErr
}

_ = f.ficsitCli.Profiles.Save()
Expand All @@ -348,6 +367,8 @@ func (f *FicsitCLI) DisableMod(mod string) error {
return errors.New("no installation selected")
}

l := slog.With(slog.String("task", "disableMod"), slog.String("mod", mod), utils.SlogPath("install", f.selectedInstallation.Info.Path))

profileName := f.selectedInstallation.Installation.Profile
profile := f.GetProfile(profileName)

Expand All @@ -366,7 +387,8 @@ func (f *FicsitCLI) DisableMod(mod string) error {
installErr := f.validateInstall(f.selectedInstallation, mod)

if installErr != nil {
return errors.Wrapf(installErr, "failed to disable mod: %s", mod)
l.Error("failed to install", slog.Any("error", installErr))
return installErr
}

_ = f.ficsitCli.Profiles.Save()
Expand Down
4 changes: 2 additions & 2 deletions backend/bindings/ficsitcli/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (f *FicsitCLI) SetProfile(profile string) error {

if installErr != nil {
l.Error("failed to validate installation", slog.Any("error", installErr))
return errors.Wrap(installErr, "Failed to validate install")
return installErr
}

return nil
Expand Down Expand Up @@ -290,7 +290,7 @@ func (f *FicsitCLI) ImportProfile(name string, file string) error {
if installErr != nil {
_ = f.ficsitCli.Profiles.DeleteProfile(name)
l.Error("failed to validate installation", slog.Any("error", installErr))
return errors.Wrap(installErr, "Failed to validate install")
return installErr
}

_ = f.ficsitCli.Profiles.Save()
Expand Down
22 changes: 17 additions & 5 deletions backend/bindings/ficsitcli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (f *FicsitCLI) CheckForUpdates() ([]Update, error) {

profile := f.GetProfile(f.selectedInstallation.Installation.Profile)

resolver := resolver.NewDependencyResolver(f.ficsitCli.Provider, viper.GetString("api-base"))
res := resolver.NewDependencyResolver(f.ficsitCli.Provider, viper.GetString("api-base"))

gameVersion, err := f.selectedInstallation.Installation.GetGameVersion(f.ficsitCli)
if err != nil {
Expand All @@ -51,10 +51,14 @@ func (f *FicsitCLI) CheckForUpdates() ([]Update, error) {
Version: ">=0.0.0",
}
}
newLockfile, err := updateProfile.Resolve(resolver, nil, gameVersion)
newLockfile, err := updateProfile.Resolve(res, nil, gameVersion)
if err != nil {
l.Error("failed to resolve dependencies", slog.Any("error", err))
return nil, errors.Wrap(err, "Error resolving dependencies")
var solvingError resolver.DependencyResolverError
if errors.As(err, &solvingError) {
return nil, solvingError
}
return nil, err //nolint:wrapcheck
}

updates := []Update{}
Expand Down Expand Up @@ -101,7 +105,11 @@ func (f *FicsitCLI) UpdateMods(mods []string) error {
err := f.selectedInstallation.Installation.UpdateMods(f.ficsitCli, mods)
if err != nil {
l.Error("failed to update mods", slog.Any("error", err))
return errors.Wrap(err, "Failed to update mods")
var solvingError resolver.DependencyResolverError
if errors.As(err, &solvingError) {
return solvingError
}
return err //nolint:wrapcheck
}

f.progress = &Progress{
Expand All @@ -118,7 +126,11 @@ func (f *FicsitCLI) UpdateMods(mods []string) error {

if err != nil {
l.Error("failed to validate installation", slog.Any("error", err))
return errors.Wrap(err, "Failed to validate installation")
var solvingError resolver.DependencyResolverError
if errors.As(err, &solvingError) {
return solvingError
}
return err
}

_ = f.ficsitCli.Profiles.Save()
Expand Down

0 comments on commit 0949c5f

Please sign in to comment.