diff --git a/cmd/gateway_validate.go b/cmd/gateway_validate.go index d3f394bcb..c3a5750db 100644 --- a/cmd/gateway_validate.go +++ b/cmd/gateway_validate.go @@ -214,19 +214,19 @@ this command unless --online flag is used. // Iterate over the input values and validate them against the keys in entityMap for _, value := range validateCmdOnlineEntitiesFilter { - // Check if the value is valid by comparing it with keys in entityMap - isValid := false - for key := range validate.EntityMap { - if value == key { - isValid = true - break + // Check if the value is valid by comparing it with keys in EntityMap + if _, exists := validate.EntityMap[value]; !exists { + // Generate an error message with the list of valid keys + listOfKeys := make([]string, 0, len(validate.EntityMap)) + for key := range validate.EntityMap { + listOfKeys = append(listOfKeys, key) } - } - if !isValid { - // Generate an error message stating that the value should be part of Kong entities - return fmt.Errorf("invalid value '%s' for --check-online-plugins-only; it should be a valid Kong entity", - value) + return fmt.Errorf( + "invalid value '%s' for --check-online-plugins-only; it should be a valid Kong entity. "+ + "Valid entities: %v", + value, listOfKeys, + ) } } return preRunSilenceEventsFlag()