Skip to content

"latest" command with no versions causes panic #33

Closed

Description

@justinfx

If the changie latest command is run in a project that contains no versions, the command panics.

reproduction:

tmp=$(mktemp -d) && cd $tmp && changie init && changie latest; rm -rf $tmp

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/miniscruff/changie/cmd.latestPipeline(0x7bb040, 0x9a74d0, 0x74f6ab, 0x4, 0x74f64b, 0x4)
	/home/user/src/go/src/github.com/miniscruff/changie/cmd/latest.go:84 +0x785
github.com/miniscruff/changie/cmd.runLatest(0x971600, 0x9a74d0, 0x0, 0x0, 0x0, 0x0)
	/home/user/src/go/src/github.com/miniscruff/changie/cmd/latest.go:40 +0x3d
github.com/spf13/cobra.(*Command).execute(0x971600, 0x9a74d0, 0x0, 0x0, 0x971600, 0x9a74d0)
	/home/user/src/go/src/github.com/spf13/cobra/command.go:850 +0x47c
github.com/spf13/cobra.(*Command).ExecuteC(0x971de0, 0x74f1a1, 0x1, 0x74f410)
	/home/user/src/go/src/github.com/spf13/cobra/command.go:958 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	/home/user/src/go/src/github.com/spf13/cobra/command.go:895
github.com/miniscruff/changie/cmd.Execute(...)
	/home/user/src/go/src/github.com/miniscruff/changie/cmd/root.go:19
main.main()
	/home/user/src/go/src/github.com/miniscruff/changie/main.go:14 +0x9d

Activity

  1. miniscruff commented on Dec 28, 2020

    @miniscruff
    Owner

    Oh, yea it seems I need a len(...) > 0 check.
    However, that brings up another question, what should latest output when you have no releases?
    Would you expect an empty string, a generic output like "no-release", maybe "v0.0.0"?

  2. justinfx commented on Dec 28, 2020

    @justinfx
    Author

    I'm not yet sure what I would expect as the output since I wasn't able to see what a normal output would be with existing releases. I was just starting to explore the interface. Is latest expected to be used programatically to capture the output and use the release version string? If so, I guess "v0.0.0". Otherwise I might expect either no output or something like "unreleased".

  3. miniscruff commented on Dec 28, 2020

    @miniscruff
    Owner

    Yea it is aimed at storing the latest release for other commands, for example if you are using goreleaser. Changie uses it in the release workflow here https://github.com/miniscruff/changie/blob/main/.github/workflows/release.yml#L22.

    Edit: I will use v0.0.0 as it is the default value go mod uses when pulling in untagged repos.

  4. self-assigned this
    on Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions