Conversation
Codecov Report
@@ Coverage Diff @@
## 2.x #2196 +/- ##
============================================
- Coverage 96.04% 95.75% -0.29%
- Complexity 1530 1534 +4
============================================
Files 50 50
Lines 3892 3911 +19
============================================
+ Hits 3738 3745 +7
- Misses 154 166 +12
Continue to review full report at Codecov.
|
|
@gchtr Looks good! I pulled it down to add an application and test coverage. Let me know if I got all that right. I think while this is open and fresh we should go ahead and add the info to the docs. Of these, I think this is the way to go:
Perhaps "Debugging & Error Logging"? This is something I do with internal documentation a lot at Upstatement. Rather than a section/folder/document be one thing, making something "This & That" communicates that it's both "this", "that', and everything in between. |
@jarednova Sounds good! I’ll keep working on this. |
gchtr
left a comment
There was a problem hiding this comment.
As always when I work on documentation, I take a close look at how stuff works and learn tons in the process of it.
@jarednova and @acobster, before I make any changes to this pull request, I wanted to get your opinion on some of my thoughts. Please see the review comments. I have the updated guide ready locally, but depending on what we decide here, I’ll have to work on it some more.
I figured that we use both error_log() and trigger_error(). Until now, I never really looked at what the difference is. Apparently, when we use error_log(), we log directly to the log. But when we use trigger_error(), it first runs through error handlers set through set_error_handler().
The set_error_handler() function is what plugins like Query Monitor or Bugsnag use to catch errors and handle them their way. For example, Bugsnag will send you emails with the error, which is very helpful. If we use error_log(), these plugins can’t catch the errors. Errors might be lost in a log that nobody looks at.
I think it might help if we:
- Deprecate the
Helper::error_log()function and introduce aHelper::trigger_error()function. - Update the
Helper::warn()function to use theHelper::trigger_error()function, too. - Introduce the same functionality to
Helper::trigger_error()that we have inHelper::doing_it_wrong()andHelper::deprecated(). This would mean something like the following.
public static function trigger_error( $message, $type = E_USER_NOTICE ) {
do_action( 'timber/trigger_error_run', $message, $type );
if ( ! WP_DEBUG ) {
return;
}
trigger_error( '[ Timber ] ' . $message, $type );
}I think that would make error handling in Timber more flexible and also be in line with @acobster’s comment in #2073 (comment).
This is a confusing hook name IMO. If we're going to introduce a new hook, why not simplify to, say,
The difference being that the former is not affected by Or is that the only way that |
... and WordPress makes it weirder. My take is two-fold. First, I'm persuaded that My only pushback is in the scope of this ticket and PR. Does the current code satisfy what was needed by #2073 (comment), #2145 with the Of course, if you really see it as just as a few tweaks away from resolving, go for it! But if there's a risk that it opens up additional rounds of Qs/considerations, I think it better to isolate. |
Hm... 🤔 yes. That’s indeed not good. Damn … The question then is, do we advise developers to use the From what I saw But then, if we advise to use
Well, if we leave this pull request at the current state, we have consistency with how WordPress does it. But we can’t add documentation for Advanced Error Logging then, because we would first need to decide how to do it right. I guess it is a rabbit hole. We should take the time to explore how it’s properly done in the WordPress context. I’ll clean this up next week for a final review and open a separate issue to work on in the future. |
|
@jarednova @acobster Back to you for review. |
jarednova
left a comment
There was a problem hiding this comment.
I like this all very much — let's do it!
|
If @jarednova is happy, I'm happy! |
Ticket: #2073 (comment), #2145
Issue
In #2073 (comment) and the following comments, we discussed whether we should use Exceptions or work with calls to
Helper::doing_it_wrong().Solution
This pull request pulls out the
Helper::doing_it_wrong()function I added in #2145 and adds improvements.I would like to go with the solution that @acobster suggested in #2073 (comment) and move the calls to
doing_it_wrong_runanddeprecated_function_runin front of the bailout check withWP_DEBUG.Impact
To say it in @acobster’s words:
When we look at
_doing_it_wrong()and_deprecated_function()in WordPress Core, the two action hooksdoing_it_wrong_runanddeprecated_function_runalso run before a check toWP_DEBUG, so this change will make error handling work the same as in WordPress, which is a good thing.Usage Changes
This will make it possible for developers to hook into their favorite logging service, be it with PHP Exceptions itself:Or, for example, with a service like Bugsnag:Ignore the code examples above. It’s not clear yet what the best way is for developers to hook into this.
Considerations
We should probably add documentation about this. I wonder whether the Debugging Guide is the right place for this or whether
Testing
Not directly. But if something won’t work, it will show up in testing, because a lot of tests that run functions including calls to
Helper::doing_it_wrong()andHelper::deprecated()will require these two functions to work properly.