fishworks / gofish

Keep your fish fresh! :tropical_fish:
https://gofi.sh
Apache License 2.0
811 stars 64 forks source link

gofish upgrade panics and fails when barrel is not installed #135

Closed karuppiah7890 closed 5 years ago

karuppiah7890 commented 5 years ago

I had installed terraform manually. Assuming I had installed it using gofish, I ran upgrade and got this error

$ gofish upgrade terraform
==> Rigs updated!
NAME
github.com/fishworks/fish-food

🐠  rigs updated in 2.193649306s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x13bff59]

goroutine 1 [running]:
github.com/fishworks/gofish/vendor/github.com/Masterminds/semver.(*Version).String(0x0, 0x9, 0xc0003fe1b0)
        /go/src/github.com/fishworks/gofish/vendor/github.com/Masterminds/semver/version.go:113 +0x69
main.newUpgradeCmd.func1(0xc000186780, 0xc00005d8d0, 0x1, 0x1, 0x0, 0x0)
        /go/src/github.com/fishworks/gofish/cmd/gofish/upgrade.go:43 +0x163
github.com/fishworks/gofish/vendor/github.com/spf13/cobra.(*Command).execute(0xc000186780, 0xc00005d890, 0x1, 0x1,
0xc000186780, 0xc00005d890)
        /go/src/github.com/fishworks/gofish/vendor/github.com/spf13/cobra/command.go:756 +0x473
github.com/fishworks/gofish/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc00017e780, 0xc000186500, 0xc000186
780, 0xc000186a00)
        /go/src/github.com/fishworks/gofish/vendor/github.com/spf13/cobra/command.go:846 +0x2fd
github.com/fishworks/gofish/vendor/github.com/spf13/cobra.(*Command).Execute(0xc00017e780, 0xc000145f88, 0xc00002c1
18)
        /go/src/github.com/fishworks/gofish/vendor/github.com/spf13/cobra/command.go:794 +0x2b
main.main()
        /go/src/github.com/fishworks/gofish/cmd/gofish/gofish.go:61 +0x3b

On noticing, I saw that it fails at this line https://github.com/fishworks/gofish/blob/6b8aaa5bf6362c8f945080b257c2a50a336eada1/cmd/gofish/upgrade.go#L38 where there's a safe assumption that there will be at least one installed version, but that's not true, as the length of installedVersions has not been checked here https://github.com/fishworks/gofish/blob/6b8aaa5bf6362c8f945080b257c2a50a336eada1/cmd/gofish/upgrade.go#L28 as compared to other usages of findFoodVersions, for example in info command where it clearly gives an error that there are no installed versions https://github.com/fishworks/gofish/blob/9251fee4a28007ae5374fbae0607bb4a7b0839e2/cmd/gofish/info.go#L33

I think something similar could be done in upgrade. May be like this:

$ gofish upgrade terraform
==> Rigs updated!
NAME
github.com/fishworks/fish-food

🐠  rigs updated in 2.34935729s
==> terraform: no installed versions to upgrade
🐠  Everything up to date!
karuppiah7890 commented 5 years ago

I'll raise a PR based on the above. If there's a change in the UI/UX of the command, we can discuss it and make the changes 😄