only warn logger if present#905
Conversation
|
|
||
| def log_version_errors(version, action) | ||
| version.logger.warn( | ||
| version.logger&.warn( |
There was a problem hiding this comment.
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.
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.
OK that is certainly a fair critique. I can resubmit with the conditional inlined explicitly.
There was a problem hiding this comment.
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.loggerset.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
warnon a logger if one is present, eliminating possible sources of 500 errors and allowing developers to usepaper_trailwithout explicitly setting a logger class forPaperTrail::VersionorActiveRecord::Base