From 23736c9b30d0d82bc3dd9d7a472923b1dfd10645 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 7 Jan 2026 20:12:49 +0000 Subject: [PATCH 1/3] Initial plan From 9233c90b72fa619881da934c3976561c7c131667 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 7 Jan 2026 20:29:44 +0000 Subject: [PATCH 2/3] Extract validation message to constant to follow DRY principle Co-authored-by: spboyer <7681382+spboyer@users.noreply.github.com> --- cli/azd/cmd/env.go | 4 ++-- cli/azd/pkg/environment/environment.go | 3 +++ cli/azd/pkg/environment/manager.go | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/azd/cmd/env.go b/cli/azd/cmd/env.go index fd1f24c9999..cadbb83addf 100644 --- a/cli/azd/cmd/env.go +++ b/cli/azd/cmd/env.go @@ -852,9 +852,9 @@ func (e *envListAction) Run(ctx context.Context) (*actions.ActionResult, error) if invalidCount > 0 { warning := fmt.Sprintf( - "\n⚠ Warning: %d environment(s) have invalid names and may cause issues with azd commands. "+ - "Valid names can only contain: a-z, A-Z, 0-9, -, (, ), _, . (max 64 chars)\n", + "\n⚠ Warning: %d environment(s) have invalid names and may cause issues with azd commands. %s\n", invalidCount, + environment.EnvironmentNameValidationMessage, ) fmt.Fprint(e.writer, warning) } diff --git a/cli/azd/pkg/environment/environment.go b/cli/azd/pkg/environment/environment.go index 761c024872b..68d612e1927 100644 --- a/cli/azd/pkg/environment/environment.go +++ b/cli/azd/pkg/environment/environment.go @@ -136,6 +136,9 @@ var EnvironmentNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9-\(\)_\.]{1,64}$`) // The maximum length of an environment name. var EnvironmentNameMaxLength = 64 +// EnvironmentNameValidationMessage is the message describing valid environment name constraints +const EnvironmentNameValidationMessage = "Valid names can only contain: a-z, A-Z, 0-9, -, (, ), _, . (max 64 chars)" + func IsValidEnvironmentName(name string) bool { return EnvironmentNameRegexp.MatchString(name) } diff --git a/cli/azd/pkg/environment/manager.go b/cli/azd/pkg/environment/manager.go index db605add33b..dc87d5485dc 100644 --- a/cli/azd/pkg/environment/manager.go +++ b/cli/azd/pkg/environment/manager.go @@ -409,8 +409,9 @@ func (m *manager) Get(ctx context.Context, name string) (*Environment, error) { // Validate environment name if !IsValidEnvironmentName(name) { return nil, fmt.Errorf( - "environment name '%s' is invalid. Valid names can only contain: a-z, A-Z, 0-9, -, (, ), _, . (max 64 chars)", + "environment name '%s' is invalid. %s", name, + EnvironmentNameValidationMessage, ) } From 98ea675d1ea6a53b18735925ac9c968c2451c7db Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 7 Jan 2026 20:36:34 +0000 Subject: [PATCH 3/3] Standardize all validation messages to use the constant Co-authored-by: spboyer <7681382+spboyer@users.noreply.github.com> --- cli/azd/pkg/environment/manager.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/azd/pkg/environment/manager.go b/cli/azd/pkg/environment/manager.go index dc87d5485dc..64109290122 100644 --- a/cli/azd/pkg/environment/manager.go +++ b/cli/azd/pkg/environment/manager.go @@ -272,11 +272,13 @@ func (m *manager) loadOrInitEnvironment(ctx context.Context, environmentName str if environmentName != "" && !IsValidEnvironmentName(environmentName) { fmt.Fprintf( m.console.Handles().Stdout, - "environment name '%s' is invalid (it should contain only alphanumeric characters and hyphens)\n", - environmentName) + "environment name '%s' is invalid. %s\n", + environmentName, + EnvironmentNameValidationMessage) return nil, false, fmt.Errorf( - "environment name '%s' is invalid (it should contain only alphanumeric characters and hyphens)", - environmentName) + "environment name '%s' is invalid. %s", + environmentName, + EnvironmentNameValidationMessage) } // No environment name, no default environment set. @@ -581,7 +583,8 @@ func (m *manager) ensureValidEnvironmentName(ctx context.Context, spec *Spec) er func invalidEnvironmentNameMsg(environmentName string) string { return fmt.Sprintf( - "environment name '%s' is invalid (it should contain only alphanumeric characters and hyphens)\n", + "environment name '%s' is invalid. %s\n", environmentName, + EnvironmentNameValidationMessage, ) }