Skip to content

Commands crash with index out of range when an optional identifier is omitted #627

Description

@NickJosevski

The bug

Three commands index args[0] without checking that any argument was supplied, and without an Args constraint to reject the empty case. Running them with no identifier panics instead of prompting or reporting an error.

Commands to reproduce

octopus project variables list
octopus project branch list
octopus project-group delete

Outcome

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

goroutine 1 [running]:
github.com/OctopusDeploy/cli/pkg/cmd/project/variables/list.NewCmdList.func1(...)
	pkg/cmd/project/variables/list/list.go:75
github.com/spf13/cobra.(*Command).execute(...)
Command Site
project variables list pkg/cmd/project/variables/list/list.go:75
project branch list pkg/cmd/project/branch/list/list.go:77
project-group delete pkg/cmd/projectgroup/delete/delete.go:44

The first two are the if opts.Project.Value == "" { opts.Project.Value = args[0] } pattern, reached whenever neither -p nor a positional argument is given. The third assigns IdOrName: args[0] unconditionally.

Other commands using the same shape are unaffected because they guard first — target delete, worker delete and workerpool delete all check util.Empty(args), and the */shared/view.go helpers are safe because every caller sets Args: usage.ExactArgs(1).

Related: these commands should prompt, not fail

Once the crash is guarded, the natural behaviour is to prompt rather than error, which is what the rest of the CLI does in interactive mode:

  • project-group delete already has the promptPromptMissing at delete.go:78 selects a project group when IdOrName is empty. It is simply unreachable because the panic happens first. Guarding the argument is the whole fix.
  • project variables list and project branch list fall through to must supply project identifier, where sibling commands such as tenant variables update offer a selector.

Versions

cli: reproduced on main (25ce4fb)

Octopus Server: N/A — the panic happens during argument handling, before any API call

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions