Skip to content

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

Merged
gcf-merge-on-green[bot] merged 4 commits intogoogleapis:mainfrom
alvarowolfx:improv-null-field-err
Sep 2, 2022
Merged

feat(bigquery): improve error when reading null values#6566
gcf-merge-on-green[bot] merged 4 commits intogoogleapis:mainfrom
alvarowolfx:improv-null-field-err

Conversation

@alvarowolfx
Copy link
Copy Markdown
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 review from a team and loferris 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
@alvarowolfx alvarowolfx requested a review from shollyman August 25, 2022 18:26
Copy link
Copy Markdown
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!

Comment thread bigquery/value.go
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
Copy Markdown
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