Skip to content

Commit

Permalink
CA-398138: Handle enum value unknown error for Go SDK
Browse files Browse the repository at this point in the history
Signed-off-by: xueqingz <[email protected]>
  • Loading branch information
xueqingz committed Sep 19, 2024
1 parent ba3b3ac commit 8cf4d11
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ocaml/sdk-gen/go/templates/ConvertEnum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions ocaml/sdk-gen/go/templates/Enum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const (
//{{#doc}} {{.}}{{/doc}}
{{name}} {{type}} = "{{value}}"
{{/values}}
// The value does not belong to this enumeration
{{name}}Unrecognized {{name}} = "unrecognized"
)

{{/enums}}
2 changes: 2 additions & 0 deletions ocaml/sdk-gen/go/test_data/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
2 changes: 1 addition & 1 deletion ocaml/sdk-gen/go/test_data/enum_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 8cf4d11

Please sign in to comment.