fix: Return an error on type mismatch rather than panic (#4995) #5341
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #4995.
Rationale for this change
An error with a nice message is better for users than a panic in this case.
What changes are included in this PR?
I replaced an assertion with returning an error that includes the field name.
Are there any user-facing changes?
Previously, this code would panic if given unsupported inputs-- now it returns an error.
I added a bit of documentation on
ArrowWrite::write
that's where I would look for it, that explains what a user might do at that level that would return this error from the inner function.