-
Notifications
You must be signed in to change notification settings - Fork 899
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
only warn logger if present #905
only warn logger if present #905
Conversation
@@ -502,7 +502,7 @@ def habtm_assoc_ids(habtm_assoc) | |||
end | |||
|
|||
def log_version_errors(version, action) | |||
version.logger.warn( | |||
version.logger&.warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the ampersand character do in this context?
Does it not make more sense to just wrap these statements on a if
block that checks to see if version.logger
is not nil
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I understand now, however according to this stackoverflow post, this functionality was introduced in Ruby 2.3, which would make the gem unusable with earlier Ruby versions, which is not desirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK that is certainly a fair critique. I can resubmit with the conditional inlined explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great. I think we can just wrap it in a if version.logger
...
The question is whether there should be an else
which logs it to STDOUT
or something, do you have thoughts on that?
@batter what do you make of the most recent change, replacing |
This will prevent people from disabling output, which I assume is the goal of setting |
I suppose @jaredbeck is probably right. Personally I would prefer to see feedback but I know not everyone wants that, and we've gotten complaints in the past from some users who had difficulty silencing warnings that PaperTrail was passing, so I think the original proposed |
@batter sounds good, changed it back to plain vanilla |
Looks good to me, and the tests are passing. Can you squash this into a single commit, then I think it's ready to merge, cheers! |
5207a55
to
22861d6
Compare
Great, all squashed. Thanks! |
Cheers! |
Released in 6.0.2 |
Currently it is possible to run into this error message:
private method 'warn' called for nil:NilClass
, which will crash apps that do not haveActiveRecord::Base.logger
set.It's a little confusing to draw a straight line from the original source of the error (
"Attribute #{k} does not exist on #{version.item_type} (Version id: #{version.id})."
) to the error message currently displayed in the console.I would think it would be preferable to only call
warn
on a logger if one is present, eliminating possible sources of 500 errors and allowing developers to usepaper_trail
without explicitly setting a logger class forPaperTrail::Version
orActiveRecord::Base