From 73e3c3eb48563cafcaada84e27319400bf932935 Mon Sep 17 00:00:00 2001 From: Sai Ram Date: Sat, 24 Oct 2026 00:45:18 +0530 Subject: [PATCH] Return an error when deployment create has no app config (#2421) When the CLI detects a platform version below 1.0.0, create has no --cluster-id flag and reuses the app config fetched at startup. If that lookup failed, deployment.Create panicked on the nil config. Return errNoAppConfig instead, as v2 does. Co-authored-by: Sai Ram <4089996+vjsairam@users.noreply.github.com> --- cmd/apc/deployment.go | 8 ++++++++ cmd/apc/deployment_test.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/cmd/apc/deployment.go b/cmd/apc/deployment.go index 6c9e71836..8c74c6569 100644 --- a/cmd/apc/deployment.go +++ b/cmd/apc/deployment.go @@ -1,6 +1,7 @@ package apc import ( + "errors" "fmt" "io" @@ -60,6 +61,10 @@ var ( clusterID string deploymentMode string + // errNoAppConfig is a create with no platform settings to read: the + // lookup when the tree was built failed, and none was asked for since. + errNoAppConfig = errors.New("could not read this platform's settings for a new Deployment; check your login and try again") + hibernateUntil string hibernateForDuration string hibernateRemove bool @@ -565,6 +570,9 @@ func deploymentCreate(cmd *cobra.Command, out io.Writer) error { return fmt.Errorf("failed to get app config: %w", err) } } + if appConfig == nil { + return errNoAppConfig + } // Silence Usage as we have now validated command input cmd.SilenceUsage = true diff --git a/cmd/apc/deployment_test.go b/cmd/apc/deployment_test.go index 963a56000..b53386981 100644 --- a/cmd/apc/deployment_test.go +++ b/cmd/apc/deployment_test.go @@ -342,6 +342,20 @@ func (s *Suite) TestDeploymentCreateCommandAppConfigLookupFails() { api.AssertNotCalled(s.T(), "CreateDeployment", mock.Anything) } +func (s *Suite) TestDeploymentCreateCommandNoAppConfig() { + previousAppConfig, previousClient := appConfig, houstonClient + defer func() { appConfig, houstonClient = previousAppConfig, previousClient }() + appConfig = nil + + api := new(mocks.ClientInterface) + api.On("GetPlatformVersion", nil).Return("0.25.0", nil) + + houstonClient = api + _, err := execDeploymentCmd("create", "--label=new-deployment-name", "--executor=celery") + s.ErrorIs(err, errNoAppConfig) + api.AssertNotCalled(s.T(), "CreateDeployment", mock.Anything) +} + func (s *Suite) TestDeploymentCreateWithTypeDagDeploy() { s.Run("user should not be prompted if deployment type is not dag_deploy", func() { appConfig = &houston.AppConfig{