Commit 19a9f0c
committed
bug symfony#65637 [Console][FrameworkBundle] Fix profiling a command stopped at ConsoleEvents::COMMAND (Spomky)
This PR was merged into the 6.4 branch.
Discussion
----------
[Console][FrameworkBundle] Fix profiling a command stopped at ConsoleEvents::COMMAND
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | -
| License | MIT
A listener may stop a command at `ConsoleEvents::COMMAND`, by calling `$event->disableCommand()` or by throwing. The command then never runs, yet `ConsoleEvents::TERMINATE` is still dispatched and `ConsoleProfilerListener` still collects the profile.
That profile is read off the `TraceableCommand`, which records `input`, `output`, `arguments` and `options` from inside `run()`, the method that was never called. All four are typed properties with no default, so `--profile` replaces the reason the command was stopped with:
```
Error: Typed property Symfony\Component\Console\Command\TraceableCommand::$input
must not be accessed before initialization
```
thrown out of `CliRequest::getUri()`, then the same for `$arguments` out of `CommandDataCollector::collect()`. The command reports a failure that has nothing to do with why it was stopped, and no profile is saved for the very run one wanted to look at.
`ConsoleProfilerListener` already records the exit code and the interrupting signal on the `TraceableCommand` before collecting. It now also records the input, the output, the arguments and the options when the command never got to record them itself. The terminate event carries the input after it was bound to the command definition, so the profile of a stopped command lists its arguments and options the same way as the profile of a command that ran. Nothing a command that does run records is affected, since `run()` assigns all four itself and the guard then skips them.
One more thing on the same path: `CliRequest::getResponse()` returned an anonymous `Response` overriding `getStatusCode()`, which is ``@final``, so every profiled command emitted a self deprecation. An exit code is not an HTTP status and does not pass the validation in `setStatusCode()`, where `0` and `113` are both rejected, so the property is written directly instead.
Three tests come with it, on a path that had no coverage until now: a command stopped by a listener that disables it, a command stopped by a listener that throws, and a command that runs.
Found while writing a console listener that denies access at `ConsoleEvents::COMMAND`.
Commits
-------
fe42885 [Console][FrameworkBundle] Fix profiling a command stopped at ConsoleEvents::COMMAND5 files changed
+151-7Lines changed: 151 additions & 7 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- src/Symfony
- Bundle/FrameworkBundle
- EventListener
- Tests/Functional
- app/ConsoleProfiler
- Component/Console/Debug
Expand file treeCollapse file tree
Open diff view settings
Collapse file
src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php
Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php+11-2Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
122 | 122 | |
123 | 123 | |
124 | 124 | |
125 | | - |
126 | | - |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
127 | 136 | |
128 | 137 | |
129 | 138 | |
|
Collapse file
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConsoleProfilerTest.php
Copy file name to clipboard+108Lines changed: 108 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
Collapse file
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ConsoleProfiler/bundles.php
Copy file name to clipboard+16Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
Collapse file
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ConsoleProfiler/config.yml
Copy file name to clipboard+13Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
Collapse file
src/Symfony/Component/Console/Debug/CliRequest.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Debug/CliRequest.php+3-5Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | | - |
| 52 | + |
53 | 53 | |
54 | 54 | |
55 | | - |
56 | 55 | |
57 | | - |
58 | | - |
59 | | - |
| 56 | + |
| 57 | + |
60 | 58 | |
61 | 59 | |
62 | 60 | |
|
0 commit comments