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

Check if ok when casting Scan src to string #33

Closed
wants to merge 2 commits into from

Conversation

theFong
Copy link
Contributor

@theFong theFong commented Jan 20, 2024

No description provided.

@bojanz
Copy link
Owner

bojanz commented Jan 20, 2024

Thanks!

In what case would this happen? Can we add a test for it?

@theFong
Copy link
Contributor Author

theFong commented Jan 20, 2024

I'm using this library here: https://github.com/jinzhu/copier and it will try to set fields differently if the object is a sql.Scanner. Proper error response appears important.

https://github.com/jinzhu/copier/blob/master/copier.go#L625

Will add a test!

@theFong
Copy link
Contributor Author

theFong commented Jan 20, 2024

Added test to cover new error case!

input := src.(string)
input, ok := src.(string)
if !ok {
return fmt.Errorf("invalid src: %v", src)
Copy link
Owner

Choose a reason for hiding this comment

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

This error does not tell us why the value is invalid.

What if we did this instead:

return fmt.Errorf("value is not a string: %v", src)

@bojanz
Copy link
Owner

bojanz commented Feb 18, 2024

@theFong
I apologize for losing track of your MR, work got a bit busy. I left one last comment for a possible improvement, then we can merge this.

@bojanz
Copy link
Owner

bojanz commented Apr 19, 2024

Tweaked and committed in cf9e73a. Cheers!

@bojanz bojanz closed this Apr 19, 2024
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.

2 participants