Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate enum values #794

Merged
merged 7 commits into from
Dec 28, 2020
Merged

Validate enum values #794

merged 7 commits into from
Dec 28, 2020

Conversation

zippolyte
Copy link
Contributor

@zippolyte zippolyte commented Dec 17, 2020

Add a validate function to all enum values for clear error messages and fail early to avoid sending bad payloads to API
Fixes #787

@zippolyte zippolyte requested review from a team as code owners December 17, 2020 16:16
therve
therve previously approved these changes Dec 18, 2020
@zippolyte zippolyte requested review from a team as code owners December 18, 2020 12:38
@zippolyte zippolyte changed the title Validate palette enum Validate enum values Dec 18, 2020
@therve
Copy link
Contributor

therve commented Dec 18, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

romainberger
romainberger previously approved these changes Dec 18, 2020
Copy link
Member

@romainberger romainberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for Synthetics 👍

Copy link
Contributor

@therve therve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a small but annoying comment.

@@ -5622,25 +5653,234 @@ func buildTerraformHostmapRequestStyle(datadogStyle datadogV1.HostMapWidgetDefin
}

// Schema validation
func validateWidgetPalette(val interface{}, key string) (warns []string, errs []error) {
_, err := datadogV1.NewWidgetPaletteFromValue(val.(string))
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a little bit of elbow grease, I feel that we could define a wrapper function that you can directly assign to ValidateFunc. Seems non trivial. In the mean time, please inline the err check like if _, err := ..; err != nil

therve
therve previously approved these changes Dec 28, 2020
Copy link
Contributor

@therve therve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome, one minor nit.

arg := reflect.ValueOf(val)
outs := reflect.ValueOf(newEnumFunc).Call([]reflect.Value{arg})
err := outs[1].Interface()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please inline the condition withe previous line.

@zippolyte zippolyte merged commit 0d124c2 into master Dec 28, 2020
@zippolyte zippolyte deleted the hippo/ve branch December 28, 2020 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Widget with invalid palette name fails with incomprehensible error and stays broken until dashboard is deleted
4 participants