Problem/Motivation
1) always catch \Throwable, not \Exception
2) always pass the old exception when re-throwing it. Otherwise, we lose the backtrace.
example --
try {
$ignored_paths = $this->getIgnoredPaths();
}
catch (\Exception $e) {
throw new StageException($e->getMessage());
}
… but we should really do this everywhere where Stage is currently catching exceptions.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork automatic_updates-3341224
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
omkar.podey commented\Throwableover\Exception?I changed the code to catch
\Throwableinstead of\Exception(\Throwable covers both php errors and exceptions)\Throwableallows us to do that.Is that what you were thinking @phenaproxima ? or am i missing something ?
Comment #4
omkar.podey commentedComment #5
wim leersFor #3.1 to be actually true, we should apply this pattern far more widely than only when
trying$ignored_paths = $this->getIgnoredPaths();.Assigning to @phenaproxima for review on both #3 and the preceding paragraph.
Comment #6
wim leersAlso, isn't this basically proposing to do a superset of #3277034: Unhandled Composer Stager exceptions leave the update process in an indeterminate state?
Comment #7
phenaproximaThis is what I'm thinking. I don't see any reason, generally, for us to treat errors and exceptions any differently in Package Manager and AU. (If there is such a case, it should be one-off and heavily commented.) To me, being resilient means we should catch and handle as many problems as we can, and that means catching \Throwable.
Comment #8
tedbowComment #9
wim leersOkay, based on #7, @phenaproxima clearly agrees with what I wrote in #5.
However … it looks like that is already the case!
But is not yet consistently implemented by
Stage. Marking for that.Comment #10
wim leersSince this affects reliability, tagging
core-mvp.Comment #11
omkar.podey commentedComment #12
omkar.podey commentedI don't see any more instances to be changed, setting to needs review
Comment #13
wim leersThe MR is still targeting
8.x-2.x😅 We need a new MR, that targets3.0.x.Comment #15
wim leers@omkar.podey: please also add
diff /var/www/html/core/scripts/dev/commit-code-check.sh modules/contrib/automatic_updates/commit-code-check.shlike I suggested during the call — that's going to make comparing this simpler.Also:
ls -al /var/www/html/coreandls -al modules/contrib/automatic_updates.All just prior to executing
modules/contrib/automatic_updates/commit-code-check.sh --drupalci.Comment #16
wim leersThis is an absolute nightmare to figure out. This approach is also a nightmare to debug. Enough. The alternative approach I've started at #3343430-8: Stop reusing core's commit-code-check.sh in favor of 4 simple commands looks promising.
For this issue: just reverting all code quality checks temporarily, so @omkar.podey can continue 👍
Comment #17
omkar.podey commentedComment #18
wim leersLooks good!
🚢
Comment #19
phenaproximaQuestion.
Do we have any other places where we are directly re-throwing a caught exception? Something like:
...because, in those cases, we are also losing the backtrace of $e, and should be wrapping those exceptions too in most cases.
Comment #20
wim leersThis.
The point is that it's not knowable what might fail, but that we have a big net, catch it, and surface it in an appropriate way. That is already the case here! 👍
I specifically checked that. See #9.
(Method used: search for
throw newin all*.phpfiles in bothsrcandpackage_manager/src.)Comment #22
phenaproximaComment #23
phenaproxima🤔 Well...
throw newwould not be the thing. It'd be more likethrow $(i.e., throwing some already-caught exception).And
grep -irn 'throw \$' .does find some stuff:Most of these seem fine. The only one that's maybe a little questionable is the one in ComposerInspector; we're re-throwing an exception from Composer Stager. IMHO that one should be wrapped. Thoughts?
Comment #24
wim leersOh!
Interesting. But that's not the pattern this issue was aiming to address, that's why I didn't check for that.
No, the one in
ComposerInspectoris 100% intentional. (That happened in #3311229: Validate compliance with composer minimum stability during PreRequireEvent after very careful deliberation.)We are not in the business of wrapping
composer-stager's exceptions inComposerInspectorbecause validators ought to handle exceptions ofcomposer-stagerthemselves.Otherwise,
\Drupal\package_manager\Validator\ComposerSettingsValidator::validate()wouldn't have to do this for example:setting.'));
return;
}
If you're arguing that
ComposerInspectorshould wrap all\PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface::run()exceptions, that'd be a different concern/discussion, and IMHO out of scope.Comment #26
phenaproximaYou've convinced me. Merged!