From 337a3471599f2bbcc6482332e11550a847cf22e1 Mon Sep 17 00:00:00 2001 From: Govind Charpe Date: Fri, 15 May 2026 13:14:32 +0530 Subject: [PATCH] fix: improve config apply validation and context switch exit codes - Added validation in \harbor config apply\ to prevent silently accepting empty or invalid configuration files. - Updated \harbor context switch\ to return a non-zero exit code and standard error format when a context is not found, improving scriptability and automation UX. Signed-off-by: Govind Charpe --- cmd/harbor/root/configurations/apply.go | 4 ++++ cmd/harbor/root/context/switch.go | 2 +- empty.yaml | 0 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 empty.yaml diff --git a/cmd/harbor/root/configurations/apply.go b/cmd/harbor/root/configurations/apply.go index d6511a0cd..d9dd64874 100644 --- a/cmd/harbor/root/configurations/apply.go +++ b/cmd/harbor/root/configurations/apply.go @@ -64,6 +64,10 @@ Make sure to run 'harbor config get' first to populate the local config file wit default: return fmt.Errorf("unsupported file type: %s, expected '.yaml/.yml' or '.json'", fileType) } + + if configurations == nil { + return fmt.Errorf("config file is empty or contains no valid configurations") + } } else { return fmt.Errorf("no config file specified") } diff --git a/cmd/harbor/root/context/switch.go b/cmd/harbor/root/context/switch.go index ee9301814..6062bee84 100644 --- a/cmd/harbor/root/context/switch.go +++ b/cmd/harbor/root/context/switch.go @@ -50,7 +50,7 @@ func SwitchContextCommand() *cobra.Command { return fmt.Errorf("failed to update config: %w", err) } } else { - fmt.Println("context doesn't exist") + return fmt.Errorf("context '%s' doesn't exist", newActiveCredential) } } else { res, err := prompt.GetActiveContextFromUser() diff --git a/empty.yaml b/empty.yaml new file mode 100644 index 000000000..e69de29bb