From 8cf4d11faf6b1167beabbb1ce28ee7c32b02979b Mon Sep 17 00:00:00 2001 From: xueqingz Date: Thu, 5 Sep 2024 07:32:49 +0000 Subject: [PATCH] CA-398138: Handle enum value unknown error for Go SDK Signed-off-by: xueqingz --- ocaml/sdk-gen/go/templates/ConvertEnum.mustache | 2 +- ocaml/sdk-gen/go/templates/Enum.mustache | 2 ++ ocaml/sdk-gen/go/test_data/enum.go | 2 ++ ocaml/sdk-gen/go/test_data/enum_convert.go | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ocaml/sdk-gen/go/templates/ConvertEnum.mustache b/ocaml/sdk-gen/go/templates/ConvertEnum.mustache index 85bb1660c2..5663d04ab0 100644 --- a/ocaml/sdk-gen/go/templates/ConvertEnum.mustache +++ b/ocaml/sdk-gen/go/templates/ConvertEnum.mustache @@ -17,7 +17,7 @@ func deserialize{{func_name_suffix}}(context string, input interface{}) (value { value = {{name}} {{/items}} default: - err = fmt.Errorf("unable to parse XenAPI response: got value %q for enum %s at %s, but this is not any of the known values", strValue, "{{type}}", context) + value = {{type}}Unrecognized } return } diff --git a/ocaml/sdk-gen/go/templates/Enum.mustache b/ocaml/sdk-gen/go/templates/Enum.mustache index 1b668dd19b..5288573e5d 100644 --- a/ocaml/sdk-gen/go/templates/Enum.mustache +++ b/ocaml/sdk-gen/go/templates/Enum.mustache @@ -6,6 +6,8 @@ const ( //{{#doc}} {{.}}{{/doc}} {{name}} {{type}} = "{{value}}" {{/values}} + // The value does not belong to this enumeration + {{name}}Unrecognized {{name}} = "unrecognized" ) {{/enums}} \ No newline at end of file diff --git a/ocaml/sdk-gen/go/test_data/enum.go b/ocaml/sdk-gen/go/test_data/enum.go index 0a0e17be7d..db0e9d6994 100644 --- a/ocaml/sdk-gen/go/test_data/enum.go +++ b/ocaml/sdk-gen/go/test_data/enum.go @@ -5,4 +5,6 @@ const ( VMTelemetryFrequencyDaily VMTelemetryFrequency = "daily" // Run telemetry task weekly VMTelemetryFrequencyWeekly VMTelemetryFrequency = "weekly" + // The value does not belong to this enumeration + VMTelemetryFrequencyUnrecognized VMTelemetryFrequency = "unrecognized" ) diff --git a/ocaml/sdk-gen/go/test_data/enum_convert.go b/ocaml/sdk-gen/go/test_data/enum_convert.go index 40129c0e5c..737436cc19 100644 --- a/ocaml/sdk-gen/go/test_data/enum_convert.go +++ b/ocaml/sdk-gen/go/test_data/enum_convert.go @@ -14,7 +14,7 @@ func deserializeEnumTaskStatusType(context string, input interface{}) (value Tas case "success": value = TaskStatusTypeSuccess default: - err = fmt.Errorf("unable to parse XenAPI response: got value %q for enum %s at %s, but this is not any of the known values", strValue, "TaskStatusType", context) + value = TaskStatusTypeUnrecognized } return } \ No newline at end of file