dapr / cli

Command-line tools for Dapr.
Apache License 2.0
321 stars 204 forks source link

Add version parsing check skip malformed versions and avoid panic #1469

Open antontroshin opened 19 hours ago

antontroshin commented 19 hours ago

Description

Fix a panic when an incorrect version is pulled from dapr releases page. For example, this happened when a new release tag vedge was introduced.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x1961f53]
goroutine 1 [running]:
github.com/hashicorp/go-version.(*Version).String(0x0)
    /home/runner/go/pkg/mod/github.com/hashicorp/go-version@v1.6.0/version.go:369 +0x33
github.com/hashicorp/go-version.(*Version).Compare(0x0, 0xc00077c000)
    /home/runner/go/pkg/mod/github.com/hashicorp/go-version@v1.6.0/version.go:116 +0x25
github.com/hashicorp/go-version.(*Version).GreaterThan(...)
    /home/runner/go/pkg/mod/github.com/hashicorp/go-version@v1.6.0/version.go:298
github.com/dapr/cli/pkg/version.GetLatestReleaseGithub.func1({0xc00106a000, 0x35bebd, 0x41e000})
    /home/runner/work/cli/cli/pkg/version/version.go:124 +0x1d4
github.com/dapr/cli/pkg/version.GetVersionFromURL({0xc0005fa2a0, 0x2f}, 0x2522[19](https://github.com/dapr/dapr/actions/runs/11962935498/job/33352369506?pr=8301#step:6:20)0)
    /home/runner/work/cli/cli/pkg/version/version.go:102 +0x2b5
github.com/dapr/cli/pkg/version.GetLatestReleaseGithub({0xc0005fa2a0?, 0x2b?})
    /home/runner/work/cli/cli/pkg/version/version.go:107 +0x1f
github.com/dapr/cli/pkg/version.GetDaprVersion()
    /home/runner/work/cli/cli/pkg/version/version.go:63 +0x6a
github.com/dapr/cli/pkg/standalone.Init({0x23e4fe8, 0x6}, {0x23e4fe8, 0x6}, {0x0, 0x0}, 0x1, {0x0, 0x0}, {0x0, ...}, ...)
    /home/runner/work/cli/cli/pkg/standalone/standalone.go:215 +0x21c
github.com/dapr/cli/cmd.glob..func11(0xc000654800?, {0x23e21a3?, 0x4?, 0x23e226b?})
    /home/runner/work/cli/cli/cmd/init.go:174 +0x2f0
github.com/spf13/cobra.(*Command).execute(0x3a89480, {0xc000477d80, 0x1, 0x1})
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987 +0xaa3
github.com/spf13/cobra.(*Command).ExecuteC(0x3a86f[20](https://github.com/dapr/dapr/actions/runs/11962935498/job/33352369506?pr=8301#step:6:21))
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/dapr/cli/cmd.Execute({0x275c860?, 0x3997800?}, {0x275c85c?, 0xc0000061a0?})
    /home/runner/work/cli/cli/cmd/dapr.go:78 +0x159
main.main()
    /home/runner/work/cli/cli/main.go:27 +0x2f

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #[issue number]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

vamsitp commented 7 hours ago

@yaron2 Can you review & approve this ASAP plz...

elena-kolevska commented 6 hours ago

Would it make sense to also add the check for alpha versions too, since we're already fixing things in this part of the code? Also, e2e tests are failing.

yaron2 commented 6 hours ago

Tests are failing