-
Notifications
You must be signed in to change notification settings - Fork 108
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
Make error messages for setting with a reader more awesome #106
base: master
Are you sure you want to change the base?
Conversation
If you try and set an attribute with the reader accessor and a different named writer accessor exists the error message now tells you the name of the writer
Change the changes to reflect that private accessors are no longer named
Looks good to me. I think I'd prefer dropping the "did you mean the private writer?" in the case of a private writer. I can see arguments both ways, though, and defer to other committer(s). Anybody? |
My general inclination is that we shouldn't mention a private writer, but I don't feel particularly strongly about that. Otherwise, +1 |
16:43 @mst I think ... ah, I see what was bugging me So, basically, you probably want to check e.g. for 'accessor' as well - but then you just need to say "read-only method (attribute is not read-only and may change)" or something. Probably also worth having that sort of message if there's a 'clearer'. So instead of 'there is a private writer', we're just saying 'this attribute's value may end up changing', and then going figuring how to change it is an excercise for the reader still but at least they know it's possible. |
Here's my 2c: I don't see the harm in leaking the information that the private writer exists given that there are several other ways that someone who is prepared to violate encapsulation is already able to do so without the information supplied. I find providing the fact a writer exists a helpful hint to the person working on the module (which may be the original author months later, or someone new now maintaining it), but not providing the name sufficient so that someone who is not intimate with the source code isn't encouraged to call it from outside the internals of the module itself. Other people's opinions may differ, and I respect that, but that's my stance. |
I didn't merge this for 2.1501-TRIAL, but I'm happy to do another release soon. Did we come to a consensus as to the behaviour for public and private writers? |
No, I got busy on Friday. I was planning to take a look tomorrow. The consensus reached on public writers was this was a good idea. The suggestion that we're working on for private writers was something Anyway, this is a long was of saying: no consensus yet, I'm going to work On Sunday, July 19, 2015, Karen Etheridge notifications@github.com wrote:
|
FWIW it's bad form to create a pull request from your master branch, as the entire pull request will be wiped out and closed if you ever try to re-use master for anything else (e.g. tracking the mainline master). Keeping the PR in a separate branch and not re-using it is best. |
Where are we at with this? @2shortplanks did you have ideas for modifications? |
Several times I've been bitten by Moose telling me that I'm using a read only accessor even when the attribute is 'rw' because something has set a custom writer. The error messages aren't awesome.
With these changes when attempting to erroneously set an attribute with a read-only accessor the Moose::Exception::CannotAssignValueToReadOnlyAccessor error raised now is more informative if a writer accessor exists, suggesting that that writer be used and supplying the name of the writer if it is non private (i.e. doesn't start with an underscore).