Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:5.4fromlmillucci:errorhandler-copy-error-path
Jul 26, 2021

Conversation

@lmillucci
Copy link
Contributor

@lmilluccilmillucci commentedFeb 1, 2021
edited
Loading

QA
Branch?5.x for features
Bug fix?no
New feature?yes
Deprecations?no
Tickets
LicenseMIT
Doc PR

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:
Screenshot_2021-02-01 MyException (500 Internal Server Error)

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

@carsonbot
Copy link

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

@lmilluccilmillucciforce-pushed theerrorhandler-copy-error-path branch from1da52a0 to057e2f5CompareFebruary 1, 2021 08:11
@nicolas-grekas
Copy link
Member

Dunno why@carsonbot closed this one.

@lmillucci
Copy link
ContributorAuthor

lmillucci commentedFeb 1, 2021
edited
Loading

I think it was closed because I didn't read well the first comment
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?

I'm moving this to "ready for review"

Nyholm reacted with thumbs up emoji

<span class="trace-method"><?=$trace['function'];?></span>
<?php }?>
(line<?=$lineNumber;?>)
<button class="hidden" data-clipboard-text="<?phpechoimplode(\DIRECTORY_SEPARATOR,$filePathParts);?>">Copy path</button>
Copy link
Contributor

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.

lmillucci reacted with thumbs up emoji
@noniagriconomie
Copy link
Contributor

hello, isnt this "similar" tohttps://symfony.com/doc/current/reference/configuration/framework.html#ide?

ro0NL and Nyholm reacted with thumbs up emoji

@yceruto
Copy link
Member

yceruto commentedFeb 1, 2021
edited
Loading

hello, isn't this "similar" tohttps://symfony.com/doc/current/reference/configuration/framework.html#ide?

Yes, but not all IDEs support that feature, I think it would be worth it.

👍 on my side.

@lmilluccilmillucciforce-pushed theerrorhandler-copy-error-path branch from4620b46 to18d25cdCompareFebruary 3, 2021 13:00
@nicolas-grekasnicolas-grekas added this to the5.x milestoneFeb 4, 2021
@nicolas-grekas
Copy link
Member

Oh does the icon work in dark mode? Can you please update your screenshot?

@lmillucci
Copy link
ContributorAuthor

These are the updated screenshots:
Screenshot from 2021-02-04 11-56-46
Screenshot_2021-02-04 MyException (500 Internal Server Error)(1)

PS: What about coding standard issues found by fabbot? Should I fix them?

nicolas-grekas
nicolas-grekas previously approved these changesFeb 4, 2021
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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)

}
/* Prevents from disallowing clicks on "copy to clipboard" elements inside toggles*/
var copyToClipboardElements= toggles[i].querySelectorAll('span[data-clipboard-text]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why usingfor (...) here and.forEach at line 40.
Same foraddEventListener(element vselement.addEventListener)

Copy link
Member

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.

Copy link
ContributorAuthor

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();
Copy link
Member

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

@Nyholm
Copy link
Member

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.

Screenshot 2021-02-06 at 17 13 36

<span class="trace-method"><?=$trace['function'];?></span>
<?php }?>
(line<?=$lineNumber;?>)
<span class="icon icon-copy hidden" data-clipboard-text="<?phpechoimplode(\DIRECTORY_SEPARATOR,$filePathParts).':'.$lineNumber;?>">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think thedata-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.

Copy link
Member

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)

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?

@nicolas-grekasnicolas-grekas dismissed theirstale reviewFebruary 11, 2021 10:10

Good point raised by Nyholm.

@nicolas-grekas
Copy link
Member

I think that allowing a copy/paste of the path of the file is interesting.
In order to account for Docker/etc, we could allow passing a 3rd$format argument toFileLinkFormatter::format(), that would be used instead of$fmt[0] when possible, on the last line here:

publicfunctionformat(string$file,int$line)
{
if ($fmt =$this->getFileLinkFormat()) {
for ($i =1;isset($fmt[$i]); ++$i) {
if (0 ===strpos($file,$k =$fmt[$i++])) {
$file =substr_replace($file,$fmt[$i],0,\strlen($k));
break;
}
}
returnstrtr($fmt[0], ['%f' =>$file,'%l' =>$line]);

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?

@lmillucci
Copy link
ContributorAuthor

I think that allowing a copy/paste of the path of the file is interesting.
In order to account for Docker/etc, we could allow passing a 3rd$format argument toFileLinkFormatter::format(), that would be used instead of$fmt[0] when possible, on the last line here:

publicfunctionformat(string$file,int$line)
{
if ($fmt =$this->getFileLinkFormat()) {
for ($i =1;isset($fmt[$i]); ++$i) {
if (0 ===strpos($file,$k =$fmt[$i++])) {
$file =substr_replace($file,$fmt[$i],0,\strlen($k));
break;
}
}
returnstrtr($fmt[0], ['%f' =>$file,'%l' =>$line]);

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$format argument ofFileLinkFormatter::format(). I can add it to the function to override the default format but how should I use it in this situation?

@fabpot
Copy link
Member

I would display the copy button only on hover to avoid having too many icons on the page.

javiereguiluz and noniagriconomie reacted with thumbs up emoji

@lmillucci
Copy link
ContributorAuthor

I've updated the branch to display the icon only on hover. I'm still not sure about what should I do withFileLinkFormatter

This is an example:
copy_icon_gif

noniagriconomie and yceruto reacted with thumbs up emoji

@fabpot
Copy link
Member

@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.

@lmilluccilmillucciforce-pushed theerrorhandler-copy-error-path branch from3bee7af tod1a60bbCompareJuly 26, 2021 06:55
@lmillucci
Copy link
ContributorAuthor

@fabpot rebased 👍

@fabpotfabpotforce-pushed theerrorhandler-copy-error-path branch fromd1a60bb to5779f86CompareJuly 26, 2021 07:21
@fabpot
Copy link
Member

Thank you@lmillucci.

@fabpotfabpot merged commita19735b intosymfony:5.4Jul 26, 2021
This was referencedNov 5, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@jderussejderussejderusse left review comments

@ycerutoycerutoyceruto left review comments

@fabpotfabpotfabpot approved these changes

+1 more reviewer

@ro0NLro0NLro0NL left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

9 participants

@lmillucci@carsonbot@nicolas-grekas@noniagriconomie@yceruto@Nyholm@fabpot@jderusse@ro0NL

[8]ページ先頭

©2009-2025 Movatter.jp