Skip to content

Commit

Permalink
cmd/vinegar: wrap all needed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Feb 2, 2024
1 parent 459bb84 commit e6284ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
20 changes: 9 additions & 11 deletions cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (b *Binary) Main(args ...string) error {

logFile, err := LogFile(b.Type.String())
if err != nil {
return err
return fmt.Errorf("failed to init log file: %w", err)
}
defer logFile.Close()

Expand Down Expand Up @@ -170,7 +170,7 @@ func (b *Binary) Main(args ...string) error {
}

if err != nil {
return err
return fmt.Errorf("failed to init %s prefix: %w", b.Type, err)
}
}

Expand Down Expand Up @@ -223,7 +223,7 @@ func (b *Binary) Run(args ...string) error {

cmd, err := b.Command(args...)
if err != nil {
return err
return fmt.Errorf("%s command: %w", b.Type, err)
}

// Act as the signal holder, as roblox/wine will not do anything with the INT signal.
Expand Down Expand Up @@ -272,10 +272,9 @@ func (b *Binary) Run(args ...string) error {
}
}

// Blocks and tails file forever until roblox is dead
if err := b.Tail(lf); err != nil {
log.Println(err)
}
// Blocks and tails file forever until roblox is dead, unless
// if finding the log file had failed.
b.Tail(lf)
}()

if err := cmd.Run(); err != nil {
Expand Down Expand Up @@ -324,10 +323,11 @@ func RobloxLogFile(pfx *wine.Prefix) (string, error) {
}
}

func (b *Binary) Tail(name string) error {
func (b *Binary) Tail(name string) {
t, err := tail.TailFile(name, tail.Config{Follow: true})
if err != nil {
return err
log.Printf("WARNING: failed to tail roblox log file: %s", err)
return
}

for line := range t.Lines {
Expand All @@ -339,8 +339,6 @@ func (b *Binary) Tail(name string) error {
}
}
}

return nil
}

func (b *Binary) Command(args ...string) (*exec.Cmd, error) {
Expand Down
38 changes: 21 additions & 17 deletions cmd/vinegar/binary_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (b *Binary) FetchDeployment() error {

d, err := boot.FetchDeployment(b.Type, b.Config.Channel)
if err != nil {
return err
return fmt.Errorf("fetch %s %s deployment: %w", b.Type, b.Config.Channel, err)
}

b.Deploy = &d
Expand All @@ -46,7 +46,7 @@ func (b *Binary) Setup() error {
log.Printf("Installing %s (%s -> %s)", b.Name, b.State.Version, b.Deploy.GUID)

if err := b.Install(); err != nil {
return err
return fmt.Errorf("install %s: %w", b.Deploy.GUID, err)
}
} else {
log.Printf("%s is up to date (%s)", b.Name, b.Deploy.GUID)
Expand All @@ -56,19 +56,23 @@ func (b *Binary) Setup() error {

log.Println("Using Renderer:", b.Config.Renderer)
if err := b.Config.FFlags.Apply(b.Dir); err != nil {
return err
return fmt.Errorf("apply fflags: %w", err)
}

if err := dirs.OverlayDir(b.Dir); err != nil {
return err
return fmt.Errorf("overlay dir: %w", err)
}

if err := b.SetupDxvk(); err != nil {
return err
return fmt.Errorf("setup dxvk: %w", err)
}

b.Splash.SetProgress(1.0)
return b.GlobalState.Save()
if err := b.GlobalState.Save(); err != nil {
return fmt.Errorf("save state: %w", err)
}

return nil
}

func (b *Binary) Install() error {
Expand All @@ -80,11 +84,7 @@ func (b *Binary) Install() error {

pm, err := boot.FetchPackageManifest(b.Deploy)
if err != nil {
return err
}

if err := dirs.Mkdirs(dirs.Downloads); err != nil {
return err
return fmt.Errorf("fetch %s package manifest: %w", b.Deploy.GUID, err)
}

// Prioritize smaller files first, to have less pressure
Expand All @@ -97,12 +97,12 @@ func (b *Binary) Install() error {

b.Splash.SetMessage("Downloading " + b.Alias)
if err := b.DownloadPackages(&pm); err != nil {
return err
return fmt.Errorf("download %s packages: %w", b.Deploy.GUID, err)
}

b.Splash.SetMessage("Extracting " + b.Alias)
if err := b.ExtractPackages(&pm); err != nil {
return err
return fmt.Errorf("extract %s packages: %w", b.Deploy.GUID, err)
}

if b.Type == roblox.Studio {
Expand All @@ -115,16 +115,20 @@ func (b *Binary) Install() error {
}

if err := boot.WriteAppSettings(b.Dir); err != nil {
return err
return fmt.Errorf("appsettings: %w", err)
}

b.State.Add(&pm)

if err := b.GlobalState.CleanPackages(); err != nil {
return err
return fmt.Errorf("clean packages: %w", err)
}

if err := b.GlobalState.CleanVersions(); err != nil {
return fmt.Errorf("clean versions: %w", err)
}

return b.GlobalState.CleanVersions()
return nil
}

func (b *Binary) PerformPackages(pm *boot.PackageManifest, fn func(boot.Package) error) error {
Expand Down Expand Up @@ -179,7 +183,7 @@ func (b *Binary) SetupDxvk() error {
(!b.GlobalConfig.Player.Dxvk && !b.GlobalConfig.Studio.Dxvk) {
b.Splash.SetMessage("Uninstalling DXVK")
if err := dxvk.Remove(b.Prefix); err != nil {
return err
return fmt.Errorf("remove dxvk: %w", err)
}

b.State.DxvkVersion = ""
Expand Down

0 comments on commit e6284ba

Please sign in to comment.