jfrog-cli icon indicating copy to clipboard operation
jfrog-cli copied to clipboard

jfrog cli panics when no default config is defined

Open dimberr opened this issue 1 year ago • 1 comments

Describe the bug

When no default config is defined ("isDefault": false) in jfrog-cli.conf.v6, cli panics

Current behavior

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x14a pc=0xcae14ba]

goroutine 1 [running]:
github.com/jfrog/jfrog-cli-core/v2/utils/config.excludeRefreshableTokensFromDetails(...)
	github.com/jfrog/jfrog-cli-core/[email protected]/utils/config/config.go:82
github.com/jfrog/jfrog-cli-core/v2/utils/config.GetSpecificConfig({0x0, 0x0}, 0x1, 0x1)
	github.com/jfrog/jfrog-cli-core/[email protected]/utils/config/config.go:61 +0x27a
github.com/jfrog/jfrog-cli-core/v2/common/commands.(*CurlCommand).GetServerDetails(0xc000112140)
	github.com/jfrog/jfrog-cli-core/[email protected]/common/commands/curl.go:140 +0x178
github.com/jfrog/jfrog-cli/artifactory.newRtCurlCommand(0x1?)
	github.com/jfrog/jfrog-cli/artifactory/cli.go:1831 +0x18b
github.com/jfrog/jfrog-cli/artifactory.curlCmd(0xc0001302c0)
	github.com/jfrog/jfrog-cli/artifactory/cli.go:1821 +0x5d
github.com/urfave/cli.HandleAction({0xd078680?, 0xd20a150?}, 0x4?)
	github.com/urfave/[email protected]/app.go:524 +0x50
github.com/urfave/cli.Command.Run({{0xcd70eca, 0x4}, {0x0, 0x0}, {0xc00033dd70, 0x1, 0x1}, {0xce0d1c0, 0x41}, {0xcdd8fc9, ...}, ...}, ...)
	github.com/urfave/[email protected]/command.go:175 +0x685
github.com/urfave/cli.(*App).RunAsSubcommand(0xc000584380, 0xc00037fce0)
	github.com/urfave/[email protected]/app.go:405 +0xdfb
github.com/urfave/cli.Command.startApp({{0xcd6ff4d, 0x2}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0xcda6a34, 0x15}, {0x0, ...}, ...}, ...)
	github.com/urfave/[email protected]/command.go:380 +0xb1e
github.com/urfave/cli.Command.Run({{0xcd6ff4d, 0x2}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0xcda6a34, 0x15}, {0x0, ...}, ...}, ...)
	github.com/urfave/[email protected]/command.go:103 +0x7c5
github.com/urfave/cli.(*App).Run(0xc0001d4700, {0xc000036040, 0x4, 0x4})
	github.com/urfave/[email protected]/app.go:277 +0xb3b
main.execMain()
	github.com/jfrog/jfrog-cli/main.go:148 +0x4b5
main.main()
	github.com/jfrog/jfrog-cli/main.go:84 +0x1c

Reproduction steps

  1. add new config without "isDefault": true, e.g. jfrog-cli.conf.v6:
{
  "servers": [
    {
      "url": "https://**********/",
      "artifactoryUrl": "https://**********/artifactory/",
      "distributionUrl": "https://**********/distribution/",
      "xrayUrl": "https://**********/xray/",
      "missionControlUrl": "https://**********/mc/",
      "pipelinesUrl": "https://**********/pipelines/",
      "user": "username",
      "accessToken": "TOKEN",
      "refreshToken": "*********",
      "serverId": "my-server",
      "isDefault": false,
      "webLogin": true
    }
  ],
  "version": "6"
}
  1. run jf rt curl api/system/ping

Expected behavior

cli should not to panic, expected error message

JFrog CLI version

jf version 2.56.1

Operating system type and version

macOS

JFrog Artifactory version

No response

JFrog Xray version

No response

dimberr avatar May 10 '24 13:05 dimberr

@dimberr, Although I agree panic errors should always be prevented by the code, we strongly recommend to avoid editing the config through a text editor. The "jf c" commands should be used. For automation, to avoid interactive prompts, ensure the CI environment variable is set with true as its value.

eyalbe4 avatar May 11 '24 10:05 eyalbe4