DevelDumperBase could implements a method (::getInternalAliases()) that returns a list of methods and function considered internal for the dumper system. The list returned from this method could be very useful for dumpers that add a backtrace to the output for detecting internal methods and functions and exclude them from the backtrace.

The method could be very helpful for solving problem like #2643392: dpm()'s / Kint shows the file and line from devel module, not from where dpm() was called

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

willzyx created an issue. See original summary.

willzyx’s picture

Status: Active » Needs review
FileSize
1.31 KB
joachim’s picture

Status: Needs review » Needs work

Is this patch meant to solve the problem at #2643392: dpm()'s / Kint shows the file and line from devel module, not from where dpm() was called? It's not doing that for me -- dsm() output says:

> Called from /8-drupal/modules/contrib/devel/kint/src/Plugin/Devel/Dumper/Kint.php:32 [Drupal\kint\Plugin\Devel\Dumper\Kint->export()]

willzyx’s picture

Status: Needs work » Needs review
+++ b/src/DevelDumperBase.php
@@ -40,4 +40,41 @@ abstract class DevelDumperBase extends PluginBase implements DevelDumperInterfac
+  /**
+   * Returns a list of methods and functions which will be considered internal.
+   *
+   * The list returned from this method could be very useful for dumpers that
+   * add a backtrace to the output for detecting internal methods and functions
+   * and exclude them from the backtrace.
+   *
+   * @return array
+   *   An array of methods and functions which will be considered internal.
+   */

as the dockblock states the method in the patch does nothing by itself.. it simply provide the list of all methods and function that should be considered internal.

For solve #2643392: dpm()'s / Kint shows the file and line from devel module, not from where dpm() was called we could use the method in the kint dumper plugin for configure kint aliases. Something like

\Kint::$aliases = array_merge_recursive(\Kint::$aliases, $this->getInternalAliases());

Ben Buske’s picture

Shouldn't these functions be included in the list, because this issue isn't only about kint.

backtrace_error_handler
dargs
dcp
ddebug_backtrace
dfb
dfbt
dpq
joachim’s picture

Status: Needs review » Needs work
  1. +++ b/src/DevelDumperBase.php
    @@ -40,4 +40,41 @@ abstract class DevelDumperBase extends PluginBase implements DevelDumperInterfac
    +   * The list returned from this method could be very useful for dumpers that
    

    'could be very useful' doesn't read right for actual code. How about 'is intended for'

  2. +++ b/src/DevelDumperBase.php
    @@ -40,4 +40,41 @@ abstract class DevelDumperBase extends PluginBase implements DevelDumperInterfac
    +   *   An array of methods and functions which will be considered internal.
    

    Needs to document the nested structure of the array.

AdamPS’s picture

Version: 8.x-1.x-dev » 8.x-3.x-dev
Status: Needs work » Needs review
FileSize
1.71 KB
2.25 KB

Revised patch

  • Adds code to make it work for kint.
  • Fixes comments #5, #6-1.
  • Return a simple array instead of nested - php doesn't really make a distinction of method/function - they are all function, callable
AdamPS’s picture

Title: Add ::getInternalAliases() method to DevelDumperBase » Exclude internal funcions from backtrace

I think the test fail is unrelated

moshe weitzman’s picture

Let's rename to getInternalFunctions

AdamPS’s picture

Done #9.
New patch also fixes typo on the quote position for some of the functions in the list.

salvis’s picture

Status: Needs review » Needs work

> Called from /8-drupal/modules/contrib/devel/kint/src/Plugin/Devel/Dumper/Kint.php:32 [Drupal\kint\Plugin\Devel\Dumper\Kint->export()]

Couldn't we just check for '/devel/' (and maybe some other fragments) in the file path?

IAC, it should be a variable, so that it can be configured locally without hacking Devel.

(Also, I'm not sure against which branch this should go.)

AdamPS’s picture

Status: Needs work » Needs review

Thanks @salvis

1. Couldn't we just check for '/devel/' (and maybe some other fragments) in the file path?

No I think it doesn't work that way. It is the dumper plug-in that does the check. In the case of kint like this:

\Kint::$aliases = $this->getInternalFunctions();

I don't see any way to pass a regex.

2. IAC, it should be a variable, so that it can be configured locally without hacking Devel.

Please can you explain what scenario you are thinking of and what should be a variable? Any base dumper class can easily override getInternalFunctions() without any hacking of Devel.

3. (Also, I'm not sure against which branch this should go.)

Normally in Drupal we commit to the newest branch then maybe back-apply.

Setting back to "needs review" for response from reviewer.

salvis’s picture

2. IAC, it should be a variable, so that it can be configured locally without hacking Devel.

Please can you explain what scenario you are thinking of and what should be a variable? Any base dumper class can easily override getInternalFunctions() without any hacking of Devel.

I mean configuration. People might want to add to or remove from the list.

AdamPS’s picture

As I see it the purpose of this issue is to ensure that the internal functions of devel are excluded from backtrace. The problem is explained clearly in #2643392: dpm()'s / Kint shows the file and line from devel module, not from where dpm() was called - which I just noticed that you raised:-). When you add a dump line of code to a function my_func_to_debug, then the trace should reports the backtrace starting from my_func_to_debug, and not including the debug line of code that you added such as ksm(). So it seems to me that the list of internal functions is determined by the code present in this module - i.e. they are internal to this module (or whatever module the dumper plugin is in).

I mean configuration. People might want to add to or remove from the list.

Ah I see, thanks for clarifying. Do you have an example in mind of when this would be required?

I don't really have time to extend the patch for configuration. I propose that the patch as it stands is useful so why don't we commit it. We can raise a follow on issue for further enhancements.

salvis’s picture

Someone may want to wrap, say, dpm(), for whatever reason, and want to exclude their wrapper as well. Hard-coded lists of function names just don't feel right...

AdamPS’s picture

Someone may want to wrap, say, dpm(), for whatever reason, and want to exclude their wrapper as well.

Ah yes I see, I agree that is a valid possibility. However I would say that less than 1% of people will want to do that.

As I mentioned, unfortunately I don't have time for that. The patch as it stands is a significant improvement. Nothing in this patch makes any obstacle to adding the ability to configure extra functions later. How about if we raise a separate issue to add configuration?

I guess the alternative is to set this needs work and wait hoping that someone will feel inspired to do the work.

salvis’s picture

I'm fine to leave it at NR.

AdamPS’s picture

Thanks @salvis

salvis’s picture

Thank you, AdamPS! :-)

moshe weitzman’s picture

Status: Needs review » Fixed

Many thanks, @AdamPS.

AdamPS’s picture

Thanks @moshe weitzman

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

joachim’s picture

Title: Exclude internal funcions from backtrace » Exclude internal functions from backtrace
FileSize
1.85 KB

Here's the patch backported to 8.x-2.x, for the benefit of everyone still running that version.

joachim’s picture

Updated 8.x-2.x patch -- I finally figured out the problem with warning messages being removed!

salvis’s picture

Status: Closed (fixed) » Needs review

Anyone interested in reviewing #25 with Drupal 8.6?

moshe weitzman’s picture

If someone else can verify that this works on 2.x branch, I'll merge it.

AdamPS’s picture

Version: 8.x-3.x-dev » 8.x-2.x-dev
Status: Needs review » Patch (to be ported)

I just scanned the issue queue and it looks to me like 8.x-3.x is in good shape now - very little left in "Needs Review" or "RTBC", thanks Moshe for the recent commits. So another alternative that could be considered more forward-looking is to create a 3.x release then mark 2.x as unsupported soon after.

moshe weitzman’s picture

Just created a 3.x release - https://www.drupal.org/project/devel/releases/8.x-3.0-beta1. Final release will come soon as well. I'll leave this open for a bit in case someone really wants to backport and can verify it works.

AdamPS’s picture

Excellent, many thanks @moshe. I have been running with local patches to devel for 2 years but now running clean, the latest release is great.

moshe weitzman’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.