-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Introduce weak vendors mode #21539
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
Introduce weak vendors mode #21539
Conversation
I see two issues here:
|
|
@@ -76,6 +83,10 @@ public static function register($mode = 0) | |||
$trace = debug_backtrace(true); | |||
$group = 'other'; | |||
|
|||
$isVendor = (strpos($file, '/vendor/') !== false); |
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.
@nicolas-grekas : we're outside the while on $trace
here, so really, we're not looking at every file of the stack trace, but only at the file that has the error triggered in it.
Third issue, even more minor, some people might have a |
That means you target deprecations triggered by code in src/. Ok. For vendors, see my PR about ComposerResource. |
Actually that was wrong and has nothing to do with the stack trace, I'm looking at the |
|
Maybe I should explain a bit more the goal of this PR, I feel I'm being unclear. This is going to used way more in libs than in project, that seldom use deprecation notices themselves. @nicolas-grekas I think that's why you talk about userland vs vendors. Let there be lib X, that has n dependencies. Anytime any of the n dependencies introduces a new deprecation, I have to fix it, and no PR can be merged during that time, unless I use And that's what I do most of the time, because I don't want to shift the burden of fixing these to anyone who wants to contribute anything unrelated to the vendor lib, and has the bad luck of doing so at the wrong time. Now let's suppose a contributor submits a new PR, and let's suppose that that PR introduces a deprecation notice in the codebase of the lib , and by that I don't mean a deprecated call to another lib, I mean a call to In my experience, many people forget to do that, and deprecations are introduced, that could easily be avoided. See this PR where I end up doing the work that should have been done by the contributor from the start. |
Doc PR would be really nice before merging since the use case should be explained there :) |
@greg0ire the issue is that your logic looks wrong. Vendor deprecations must not be distinguished based on the location of the deprecation, but based on the caller location. |
That's precisely the case I'm trying to help fix however. There are contributors that contribute new deprecations, and forget to fix these calls. Then it get merged, but could have easily be prevented. Also, there are tests that are marked with
I'm not doing that (I think). I'm not indentify the caller location, I'm identifying the callee location. When developing a lib, the lib is always calling others or itself, but no other lib is calling my lib. So in that case, I think it's safe to want to know "is there any call to a deprecated method of my lib in the codebase of my lib?"
|
Didn't notice your comment. Will do! |
Thanks, just posted a few short notes |
@@ -50,7 +52,10 @@ public static function register($mode = 0) | |||
if (false === $mode) { | |||
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER'); | |||
} | |||
if (DeprecationErrorHandler::MODE_WEAK !== $mode && (!isset($mode[0]) || '/' !== $mode[0])) { | |||
if (!in_array($mode, array( |
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.
Missing true
as a 3rd parameter for in_array
: https://3v4l.org/hsgBm
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.
fixed, thanks!
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.
the in_array + line splits look unreadable to me - what about using two comparisons on a single line 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 it's a matter of taste, because to me the more readable version is of course mine. Plus it's less repetitive. I'll do as you say though, b/c you're probably more aware of what the sf style is.
d8442b0
to
2ea482b
Compare
I changed the code so that other modes output is no longer split into vendors / non-vendors. |
028a816
to
bd8f0b3
Compare
I fixed the colorization issue, deprecation notices are always in yellow now. |
fabbot reports errors that should be fixed. |
bd8f0b3
to
ddf0f9b
Compare
@fab{b,p}ot : fixed |
457d29b
to
15cce3b
Compare
I rebased again, can anyone review and remove the "Needs work" label? This is supposed to be finished. |
15cce3b
to
4df40df
Compare
Changed the poor man's error handler from |
@@ -160,16 +196,26 @@ public static function register($mode = 0) | |||
$colorize = function ($str) { return $str; }; | |||
} | |||
if ($currErrorHandler !== $deprecationHandler) { | |||
print_r(error_get_last()); |
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.
unrelated, and very fragile to me, should be removed from this PR
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.
Ok let's remove it.
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.
Not sure what exactly qualifies as fragile here though. I think both methods are rock solid.
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.
the link between error_get_last()
and the error handler change - maybe I'm wrong - it's still unrelated so please open another PR if you want to investigate the idea
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.
Unrelated indeed. Will do
4df40df
to
5d0dbdf
Compare
A new mode is introduced, in which deprecations coming from the vendors are not taken into account when deciding to exit with an error code. In this mode, deprecations coming from the vendors are segregated from other deprecations.
5d0dbdf
to
61fd043
Compare
This is supposed to be ready on my end, please review again. |
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.
👍
Thank you @greg0ire. |
This PR was merged into the 3.3-dev branch. Discussion ---------- Introduce weak vendors mode Deprecations coming from the vendors are segregated from other deprecations. A new mode is introduced, in which deprecations coming from the vendors are not taken into account when deciding to exit with an error code. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT | Doc PR | symfony/symfony-docs#7453 <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. - Please fill in this template according to the PR you're about to submit. - Replace this comment by a description of what your PR is solving. --> Sample output : # Weak vendor mode ## With both vendors and non-vendor errors ``` WARNINGS! Tests: 1068, Assertions: 2714, Warnings: 6, Skipped: 15. Remaining deprecation notices (1) some error: 1x 1x in SonataAdminBundleTest::testBuild from Sonata\AdminBundle\Tests Remaining vendor deprecation notices (4) Legacy deprecation notices (48) ``` Exit code is 1 ## After fixing non-vendor errors ``` WARNINGS! Tests: 1068, Assertions: 2714, Warnings: 6, Skipped: 15. Remaining vendor deprecation notices (4) Legacy deprecation notices (48) ``` Exit code is 0 # TODO - [x] fix colorization issues (vendor deprecation notices are always in red) - [x] make the vendor detection more robust - [x] make the vendor dir configurable - [x] ~figure out how to run tests and~ add more of them - [x] test on non-vendor file - [x] test on vendor file - [x] do not change the output of other modes Commits ------- 61fd043 Introduce weak vendors mode
Made a separate PR for the poor man's error handling : #21795 |
This PR was merged into the master branch. Discussion ---------- Document the weak_vendors value See symfony/symfony#21539 Commits ------- abe88c6 Document the weak_vendors value
Deprecations coming from the vendors are segregated from other
deprecations. A new mode is introduced, in which deprecations coming
from the vendors are not taken into account when deciding to exit with
an error code.
Sample output :
Weak vendor mode
With both vendors and non-vendor errors
Exit code is 1
After fixing non-vendor errors
Exit code is 0
TODO
figure out how to run tests andadd more of them