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

Specific response assertion error messages #547

Conversation

PietervdWerk
Copy link
Contributor

I've been getting the error "failed to get response body: type assertion error" and it took me quite a while to figure out what the problem was. I've copied my policy into a playground and it worked fine there (in hindsight that's obvious).

I propose a more verbose and specific error message when assertion fails. I've taken the liberty to come with some suggestions.

@PietervdWerk PietervdWerk force-pushed the specific-type-assertion-errors branch from 1851450 to bbc9d14 Compare May 2, 2024 10:32
Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me, with a minor change suggested. I wonder if it would be helpful to go one step further and say "expected x, got y" in these messages? But this is an improvement nonetheless.

@@ -307,7 +307,7 @@ func (result *EvalResult) GetDynamicMetadata() (*_structpb.Struct, error) {

metadata, ok := val.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("type assertion error")
return nil, fmt.Errorf("type assertion error, dynamic_metadata is not a map[string]interface{}")
Copy link
Member

Choose a reason for hiding this comment

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

map[string]interface{} is a Go type, not a Rego one. I'd just say "is not an object" here. Same for headers below.

@PietervdWerk PietervdWerk force-pushed the specific-type-assertion-errors branch 2 times, most recently from 8ff459d to 4a935df Compare May 8, 2024 13:22
@PietervdWerk
Copy link
Contributor Author

I've updated the error messages to be "expected x, got y". Let me me know what you think :).

anderseknert
anderseknert previously approved these changes May 8, 2024
Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

@ashutosh-narkar ashutosh-narkar force-pushed the specific-type-assertion-errors branch from 4a935df to c55648b Compare May 8, 2024 16:38
Copy link
Member

@ashutosh-narkar ashutosh-narkar left a comment

Choose a reason for hiding this comment

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

@PietervdWerk the changes lgtm. It would be great if we can update the tests to reflect these detailed error messages.

@ashutosh-narkar
Copy link
Member

@PietervdWerk this would be a good change to get in. Are you able to update the tests?

@PietervdWerk
Copy link
Contributor Author

Yes tomorrow! (I had a few days off, back to work tomorrow.)

Signed-off-by: Pieter van der Werk <pieter.vdwerk@gmail.com>
Signed-off-by: Pieter van der Werk <pieter.vdwerk@gmail.com>
@ashutosh-narkar ashutosh-narkar force-pushed the specific-type-assertion-errors branch from c969be8 to 33de40b Compare May 14, 2024 20:21
Copy link
Member

@ashutosh-narkar ashutosh-narkar left a comment

Choose a reason for hiding this comment

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

Thanks @PietervdWerk!

@ashutosh-narkar ashutosh-narkar merged commit 66197cd into open-policy-agent:main May 14, 2024
8 checks passed
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.

3 participants