Skip to content

[Console] Display file and line on Exception #21414

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

Merged
merged 1 commit into from
Sep 3, 2017
Merged

[Console] Display file and line on Exception #21414

merged 1 commit into from
Sep 3, 2017

Conversation

arno14
Copy link

@arno14 arno14 commented Jan 26, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes/no
Fixed tickets -
License MIT
Doc PR -

When an exception occured:
If you have not set a verbose mode when running the command, you don't have information about the file and the line on which the exception occured.
So you must run a second time the command but the exception may not occured this time (if based on some databases datas which have changed) and it's a waste of time if you process is very long and the exception occured at the end.

The feature #21003 solve the problem if you are in a standard Symfony edition, if you leave the default settings and if you are in dev mode

@chalasr
Copy link
Member

chalasr commented Jan 26, 2017

IMHO having only the clean exception message when not in verbose mode is good enough... just set the verbose mode if you need more.

The feature #21003 solve the problem if you are in a standard Symfony edition, if you leave the default settings and if you are in dev mode

I think it's useless to have the exception log in stderr since the ran command already writes the proper message into so it's just having two traces for the same error, which doesn't make sense to me. I just proposed to fix that in symfony/symfony-standard#1044.

@nicolas-grekas
Copy link
Member

I'm sympathetic to the intend here. I also felt bad with just the message several times.
Can you please share a screenshot with before/after situations?
IMHO, I'd even like a short exception trace like the one displayed by Exception::_toString().
It's an exception guys, we don't need to be that short. It's not a normal situation, we can display a bit more. (personal rant :) )

@javiereguiluz
Copy link
Member

My opinion is the opposite of Nico and it aligns with Robin's comments :) Symfony errors have always been human-friendly and to get the full machine-friendly details, you must add -v or -vv, etc.

Most of you will disagree with me ... but not only I'd not add the file+line, but I'd also remove the weird exception class name in the error blocks.

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Jan 29, 2017
@nicolas-grekas
Copy link
Member

But CLI apps are not like Web ones: you can wait several minutes, and get the exception.
Thought, if everything is in the logs, then fine.
About the removal of the exception class, don't forget that the message is optional.

@robfrawley
Copy link
Contributor

I too could have used this on multiple occasions with long-running processes.

@arno14
Copy link
Author

arno14 commented Jan 30, 2017

Here are some screenshot:

This is the actual exception output
screenshot_basic

The one with exception class and line (does not correspond to the actual PR, I corrected some things)
screenshot_file_line_and_line

For test:
The output with __toStringMethod
screenshot_exception_to_string

the same with -vvv option
screenshot_exception_very_verbose

An other use case is running command via cron, unless you configure your cron to run with -vvv you will have very view information if an exception occured.

@chalasr
Copy link
Member

chalasr commented Jan 30, 2017

I understand the intention too, but I still think that verbose mode should be used for that (especially in a cron), anyway console errors are now logged and you can configure the console handler for having them in stderr if wanted.

If I want more to be displayed, then I would prefer writing my own exception class or any console helper and tweak the message into (maybe could we provide such in the console?) instead of expecting the application to do it automatically.

@fabpot
Copy link
Member

fabpot commented Jan 30, 2017

I'm also against this change. Verbose modes are indeed the right way to get more information about errors. It's annoying when you run (as a user) a command and you get a stack trace displayed. That's the same when browsing the web and getting an exception message. Sure, on the CLI, it cannot be exploited like for the web, but that's not user friendly. So, I'm 👎

@nicolas-grekas
Copy link
Member

Closing as discussed, thanks for the PR anyway!

@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@nicolas-grekas
Copy link
Member

I'm reopening because I'm just wasting my time debugging transient errors, just because the console displays useless errors.
The context is a "composer install" command that runs post-scripts. One of them is failing and I have no way to add -vvv to those (because composer script).

all I get is e.g. a terse

!!    [Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]  
!!    You have requested a non-existent service "".                               

Alternatively, we could have an env var to control verbosity... But we cannot say all is fine as is. Please hint a direction that would solve the DX issue and be OK to you.

@nicolas-grekas nicolas-grekas modified the milestones: 3.3, 3.4 Aug 30, 2017
@nicolas-grekas
Copy link
Member

Note that the worst error I got in this context is (when playing with Flex+SF4):

ErrorException
preg_replace(): blablah

which is just garbage as an error message, I have no idea where this can be in the code base.

@nicolas-grekas nicolas-grekas changed the base branch from master to 3.4 August 30, 2017 16:53
@nicolas-grekas
Copy link
Member

PR ready for reconsideration, here is the new screenshot:
capture du 2017-08-30 18-49-57

@nicolas-grekas nicolas-grekas changed the title Display file and line on Exception [Console] Display file and line on Exception Aug 30, 2017
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

👍 for the new output. What I'm against is having a message looking like a trace in the output for any exception thrown in low verbosity. I will check the output of command registration errors in FWB after this, having the file+line for each error displayed through the multiple calls to doRenderException is probably not useful.

@fabpot
Copy link
Member

fabpot commented Aug 30, 2017

Do we really need the exception class on the message? Now that we have the exact file and line, that's probably a detail people don't need to care about, right?

@chalasr
Copy link
Member

chalasr commented Sep 2, 2017

I agree that the FQCN does not seem useful anymore.

@nicolas-grekas
Copy link
Member

Exception class now removed in non-verbose modes, see fixtures.

@chalasr
Copy link
Member

chalasr commented Sep 3, 2017

Thanks @arno14 and @nicolas-grekas

@chalasr chalasr merged commit 484d278 into symfony:3.4 Sep 3, 2017
chalasr pushed a commit that referenced this pull request Sep 3, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Display file and line on Exception

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes/no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

When an exception occured:
If you have not set a verbose mode when running the command, you don't have information about the file and the line on which the exception occured.
So you must run a second time the command but the exception may not occured this time (if based on some databases datas which have changed) and it's a waste of time if you process is very long and the exception occured at the end.

The feature #21003 solve the problem if you are in a standard Symfony edition, if you leave the default settings and if you are in dev mode

Commits
-------

484d278 [Console] Display file and line on Exception
chalasr pushed a commit that referenced this pull request Sep 7, 2017
…mon console exceptions (yceruto)

This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Do not display short exception trace for common console exceptions

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

![console_before](https://user-images.githubusercontent.com/2028198/30173516-edb9e42c-93c5-11e7-882e-f8b0335387b3.png)

I'd like reconsider [the new error output][1] with short exception trace always displayed at top, IMHO it's annoying for common exceptions (there is not real debugging reason, the message is clear enough) such as `Symfony\Component\Console\Exception\*` which have an impact into current CLI applications.

However, I'm proposing display it for unexpected exceptions or if verbosity is enabled:

![console](https://user-images.githubusercontent.com/2028198/30173085-94322636-93c4-11e7-81a6-bba807910e62.png)

Note @nicolas-grekas's #21414 (comment) is still covered.

 [1]: #21414

Commits
-------

47b1106 Do not display short exception trace for built-in console exceptions
This was referenced Oct 18, 2017
enumag added a commit to Kdyby/Console that referenced this pull request Dec 3, 2017
enumag added a commit to Kdyby/Console that referenced this pull request Dec 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants