Skip to content

Commit

Permalink
CA-398138: Handle enum value unknown error for Go SDK (xapi-project#5981
Browse files Browse the repository at this point in the history
)

Bug fix for Go SDK, add an default Enum value to replace raising error
for unknown Enum value.

Build new SDK and samples,  test pass XenRT job: 4100718.
  • Loading branch information
psafont authored Sep 19, 2024
2 parents ba3b3ac + 8cf4d11 commit bc10ca0
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 bc10ca0

Please sign in to comment.