uselagoon / uselagoon/lagoon-cli

Using `/lagoon config add` with an empty `~/.lagoon.yml` file produces a panic error

Open
#331 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
28
Forks
14
Avg merge
1d 2h
Merged PRs (30d)
1

Description

Describe the bug
While using the uselagoon/lagoon-cli image in a gitlab CI job, we encounter the following error when trying to configure the cli:

panic: assignment to entry in nil map

This appears to happen all the way from v0.18.0 up until the current v0.21.1

To Reproduce

In the container, run

/lagoon config add --graphql $GRAPHQL_ENDPOINT --ui $UI_URL --hostname $SSH_HOST --lagoon $LAGOON --port 22 --force

(populating the shell variables with real things, obviously)

It results in:

panic: assignment to entry in nil map

goroutine 1 [running]:
github.com/uselagoon/lagoon-cli/cmd.glob..func7(0xc00015e700?, {0x9c1242?, 0x4?, 0x9c11ee?})
	/go/src/github.com/uselagoon/lagoon-cli/cmd/config.go:169 +0x249
github.com/spf13/cobra.(*Command).execute(0xde7840, {0xc00013a580, 0xb, 0xb})
	/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xabc
github.com/spf13/cobra.(*Command).ExecuteC(0xdeba60)
	/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/uselagoon/lagoon-cli/cmd.Execute()
	/go/src/github.com/uselagoon/lagoon-cli/cmd/root.go:113 +0x1a
main.main()
	/go/src/github.com/uselagoon/lagoon-cli/main.go:8 +0xf
+ /lagoon config default --lagoon XXXX
Chosen context 'XXXX' doesn't exist in config file55 <nil>
+ /lagoon version
lagoon v0.21.1 (go1.21.8)
built 2024-03-22T03:36:21+0000
+ /lagoon config list
NAME	VERSION	GRAPHQL	SSH-HOSTNAME	SSH-PORT	SSH-KEY
+ /lagoon login
Chosen context 'amazeeio' doesn't exist in config file
+ /lagoon whoami

Expected behavior
A config entry added to ~/.lagoon.yml

Additional context

As it turns out, the error is caused by the presence of a blank ~/.lagoon.yml in the container.

Simply removing the empty config file before attempting to add a config prevents the error, and is what we're currently using as a workaround.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cmd/config.go at line 169, where the stack trace shows the panic during config add. Reproduce the command with an empty ~/.lagoon.yml, then verify that it completes without panicking and writes the requested configuration entry to the file.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.