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

Add compile-time catches for common method call mistakes with attributes #738

Merged
merged 3 commits into from
Oct 9, 2021

Conversation

jwoertink
Copy link
Member

Fixes #731

This doesn't really catch all possibilities, but should catch the bulk of what you might call on your attributes inside of an operation. We found ourselves mainly doing this on JSON attributes.. metadata["key"]? instead of metadata.value["key"]?.

@jwoertink
Copy link
Member Author

I'm 99% sure the spec failure is a race condition related to #727

# in to string interpolation. Don't override that method.
def to_s(time_format : String)
call_value_instead_error_message(".to_s(time_format)")
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these are a great addition. If there's one mistake I make all the time it's calling these methods accidentally.

This specific overload makes me a bit nervous because of the way the name of the string parameter would confuse someone who happened upon this error message through some secondary path that had nothing to do with a time format.

What if the stringified method suggestion in the error message is just .to_s(...) instead? That seems like it would lead people down an almost identical path without lending confusion where they landed here without doing anything with time formats.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like that 👍 Makes sense.

@jwoertink
Copy link
Member Author

So today I actually called if attr.nil? when I meant attr.value.nil?... However, what if you really wanted to know if the attribute itself was nil? I'm not sure if I should add that one or not 🤔

@jwoertink jwoertink merged commit 48da4d8 into master Oct 9, 2021
@jwoertink jwoertink deleted the issues/731 branch October 9, 2021 21:18
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.

Better error message when calling a method on an attribute but meant to call on the value
4 participants