-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ErrorHandler] Add button to copy the path where error is thrown #40052
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
Conversation
Hey! You, my friend, deserve a BIG HUG for making this PR. To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
1da52a0
to
057e2f5
Compare
Dunno why @carsonbot closed this one. |
I think it was closed because I didn't read well the first comment I'm moving this to "ready for review" |
@@ -25,6 +25,7 @@ | |||
<span class="trace-method"><?= $trace['function']; ?></span> | |||
<?php } ?> | |||
(line <?= $lineNumber; ?>) | |||
<button class="hidden" data-clipboard-text="<?php echo implode(\DIRECTORY_SEPARATOR, $filePathParts); ?>">Copy path</button> |
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.
should we suffix :$lineNumber
? it works well in most editors AFAIK.
hello, isnt this "similar" to https://symfony.com/doc/current/reference/configuration/framework.html#ide? |
src/Symfony/Component/ErrorHandler/Resources/views/trace.html.php
Outdated
Show resolved
Hide resolved
Yes, but not all IDEs support that feature, I think it would be worth it. 👍 on my side. |
4620b46
to
18d25cd
Compare
Oh does the icon work in dark mode? Can you please update your screenshot? |
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.
(failures are false positives)
@@ -698,6 +707,14 @@ | |||
}); | |||
} | |||
|
|||
/* Prevents from disallowing clicks on "copy to clipboard" elements inside toggles */ | |||
var copyToClipboardElements = toggles[i].querySelectorAll('span[data-clipboard-text]') |
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.
Why using for (...)
here and .forEach
at line 40.
Same for addEventListener(element
vs element.addEventListener
)
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.
It would be even better to use event delegation instead.
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.
I think that this code is actually useless because the click listener for toggle it is not attached to span elements. What do you think?
var copyToClipboardElements = toggles[i].querySelectorAll('span[data-clipboard-text]') | ||
for (var k = 0; k < copyToClipboardElements.length; k++) { | ||
addEventListener(copyToClipboardElements[k], 'click', function(e) { | ||
e.stopPropagation(); |
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.
IMHO we could always stopPropagation (and not ONLY for items in SPAN/toggle). And moving this logic at line 44
I am with @noniagriconomie. I am also a bit confused =) The way I see it, on the error page, you see the relative path to each line in the stack trace. If you click at any of them it will open in PHPStorm... if you dont have it configured that way, you will get the file opened in the broswer and there you will see the absolute path. |
@@ -25,6 +25,9 @@ | |||
<span class="trace-method"><?= $trace['function']; ?></span> | |||
<?php } ?> | |||
(line <?= $lineNumber; ?>) | |||
<span class="icon icon-copy hidden" data-clipboard-text="<?php echo implode(\DIRECTORY_SEPARATOR, $filePathParts).':'.$lineNumber; ?>"> |
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.
I think the data-clipboard-text
should contain the full path to the file - not the formatted path that links to the IDE.
This means this should contain $trace['file']
, html-escaped.
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.
I'm not sure about that... when running app in docker, absolute path is useless, while relative pat works in IDE, and console (when CWD=root of project)
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.
Ah, you're right. We do have a way to map paths from docker to host, but it is bound to the IDE URLs. Can't we use that map somehow to compute absolute paths for the host?
I think that allowing a copy/paste of the path of the file is interesting. symfony/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php Lines 49 to 59 in 4d91b8f
Then we would patch HtmlRenderer::getFileLink to also handle and forward the same optional argument. @lmillucci works for you? Can you please update the PR to account for all latest comments? |
I'm not sure about the behavior of the |
I would display the copy button only on hover to avoid having too many icons on the page. |
@lmillucci Can you rebase on the current 5.4 branch to resolve the conflicts? Ping me when it's done so that I can merge this PR. Thank you. |
3bee7af
to
d1a60bb
Compare
@fabpot rebased 👍 |
d1a60bb
to
5779f86
Compare
Thank you @lmillucci. |
As a developer I want to copy the path where an exception is thrown on my IDE to check what is the problem. At the moment I have to select the path on the error page and copy it. I think that this process could be simplified through a "copy path" button that copies the error path on the clipboard.
I was thinking about something like this:

(Page style should be improved)
Let me know what you think. If you think it is a good idea I could improve this PR