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

feat(bigquery): improve error when reading null values #6566

Merged

Conversation

alvarowolfx
Copy link
Contributor

@alvarowolfx alvarowolfx commented Aug 25, 2022

Improve error message when reading NULL values from a query and trying to fit into a struct field.

Resolves #2612

@alvarowolfx alvarowolfx requested a review from a team August 25, 2022 18:25
@alvarowolfx alvarowolfx requested a review from a team as a code owner August 25, 2022 18:25
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: bigquery Issues related to the BigQuery API. labels Aug 25, 2022
Copy link
Contributor

@shollyman shollyman left a comment

Choose a reason for hiding this comment

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

Thanks for this!

@@ -455,6 +455,10 @@ func runOps(ops []structLoaderOp, vstruct reflect.Value, values []Value) error {
err = setRepeated(field, values[op.valueIndex].([]Value), op.setFunc)
} else {
err = op.setFunc(field, values[op.valueIndex])
if errors.Is(err, errNoNulls) {
f := vstruct.Type().FieldByIndex(op.fieldIndex)
err = fmt.Errorf("bigquery: NULL cannot be assigned to field `%s` of type %s", f.Name, f.Type.Name())
Copy link
Contributor

Choose a reason for hiding this comment

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

A thing to keep an eye on for the future is whether we should have a custom error type. My suspicion is this isn't a frequent enough failure to warrant custom errors at this point, nor is it super actionable unless you're dynamically rewriting things.

@shollyman shollyman removed the request for review from loferris August 27, 2022 03:31
@alvarowolfx alvarowolfx added the automerge Merge the pull request once unit tests and other checks pass. label Sep 2, 2022
@gcf-merge-on-green gcf-merge-on-green bot merged commit e9a94c2 into googleapis:main Sep 2, 2022
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bigquery: Logging field name on error in null value setting to struct field
2 participants