Problem/Motivation
Currently, file_system service depends on three other services:
file_system:
class: Drupal\Core\File\FileSystem
arguments: ['@stream_wrapper_manager', '@settings', '@logger.channel.file']
Inside of Drupal\Core\File\FileSystem class, instance of logger is used only once in the chmod() method to log error when chmod() PHP function returns FALSE.
Not only this is a side effect, but an instance of logger.channel.file contains references to other services: requests stack, current user object. And from the source of Drupal\Core\Logger\LoggerChannel::log() method, it looks like it can even execute a database query.
Logger makes dependency tree of file_system service unnecessary complicated, and I would expect such a low-level service to have as little side-effects as possible.
Remaining tasks
None
User interface changes
None.
API changes
Change of Drupal\Core\File\FileSystem::__construct() signature.
FileSystem no longer logs any errors. This is up to the caller.
Data model changes
None.
| Comment | File | Size | Author |
|---|
Issue fork drupal-2838474
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:
- 2838474-11.x
changes, plain diff MR !4392
Comments
Comment #2
20th commentedComment #8
andypostComment #9
ndobromirov commentedI vote for solution 1 as the cleaner OO based one.
Comment #10
mxr576+1 for solution 1
Comment #11
fgmWouldn't it be better not to throw but to just have the function return an error value instead ? (like traditional C/UNIX I/O).
Comment #12
kim.pepperHere's an initial go at solution 1.
Comment #13
ndobromirov commentedSeems to be breaking the patch :D
Comment #14
kim.pepperOops!
Comment #15
andypostphp doc needs to point Optional for logger
the only regression place
Comment #17
kim.pepperThanks @andypost.
This patch should fix a few test fails related to the manual registration of the FileSystem service in install.core.inc.
Comment #19
kim.pepperFix test fails in FileSystemDeprecationTest.
Comment #20
andypostIt blocks further fixes for file system and config storage
Comment #21
kim.pepperHad a chat about this with @larowlan and couldn't find anything about a bc compatibility policy for logging. Given we are throwing exceptions, I think this means we are covered for the most part.
The only outlier is:
...which currently logs an error when scanning a directory tree and gets to a directory it can't open.
Comment #22
ndobromirov commentedA new exception should work in that case as well.
Comment #25
kim.pepperRe-roll of #19
Comment #26
kim.pepperForgot to attach the file!
Comment #27
kim.pepperRe: #22
I don't think it will, because that will halt the scan. Currently it just logs a warning and continues.
Comment #33
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #35
chi commentedThe issues is quite old. At the moment, file system makes a heavy use of the logger.
Comment #38
rpayanmPlease review.
Comment #39
kim.pepperNW for MR feedback above.
Comment #40
alexpottI think given that we have code like
we should go for solution 2 as the less disruptive for now. And leave it up to the calling code to log if necessary. In the above example, logging is actually not appropriate as this is used to inform the user.
Comment #41
alexpottHiding patches as we have an MR now.
Comment #42
alexpottI've gone for a halfway house for #40 and added $throw to \Drupal\Core\File\FileSystem::chmod() so the caller is in control.
I don't think there are any use-cases for $throw in core but I've ensured there is test coverage.
Comment #43
alexpottUpdated issue summary with latest changes.
Comment #44
mfbI updated the change record to more completely describe the impacts of logging being removed. Now I realize it needs a bit more work as I see @alexpott added an additional new change record, so they are partially redundant.
Comment #45
longwaveWhy do we need the $throw argument, the caller can detect failure via the return value already? We're already inconsistent where some methods throw exceptions and others return FALSE, but this doesn't make it any better.
Comment #46
alexpott@longwave yeah I went that way originally but then got cold feet when deleting the exception.. but I agree - let's remove $throw.
Comment #47
longwaveIf we think it's worth cleaning up, perhaps in a followup we can add deprecations in all the cases we currently return FALSE and notify users that we will start throwing exceptions instead in the next major.
Comment #48
alexpott@longwave I don't think we want that though - in the case of chod there are times that throwing an exception would lead to way more complex calling code.
Comment #49
mfb@alexpott I'd say it should still be mentioned in the change record that logging is removed from those other methods, not just chmod. But you removed my mention of those. This is relevant if the calling code caught the exception and assumed an error was already logged by the file_system service.
Comment #50
alexpott@mfb I've listed the public method that no longer log in the CR and detailed that it is the callers responsibility to log if any method results in FALSE or throws an exception.
Comment #51
kim.pepperComment #52
longwaveFixed deprecation, also fixed a nit in the docblock.
#3416354: Inject services into LoggerChannelFactory is somewhat related, there is special code in LoggerChannelFactory to handle the case where the injected dependencies are not present (during the installer, because it needs
file_system), once this dependency is gone I think that can also be removed.Comment #53
spokjeTagging with
Needs followupfor #52Comment #54
spokjeCode changes make sense and are primarily removing logging/loggers and altering comments about logging/loggers.
Checked CR and that mentions all methods involved in not being logged any more.
Tests are green.
For me this is RTBC.
Comment #55
longwaveThe followup isn't really needed until both issues land, just they overlap a bit, so we can probably fix it directly in whichever lands second - removing the tag.
Comment #56
spokjeI'm glad somebody is an optimist and is sure we'll remember ;)
Comment #57
longwaveWell it's only a bit of dead code if we don't. And #3416697: Remove install container definitions of FileSystem and StreamWrapperManager is making me think that this might not even get used...
Comment #58
socialnicheguru commentedI am saying that I thought that this issue would help me solve circular recurrence. But it did not.
I applied this #2838474: Remove dependency of "file_system" service on "logger" I get this:
Circular reference detected for service "workspaces.manager", path: "scheduler.manager -> dat
e.formatter -> workspaces.manager -> logger.channel.workspaces -> logger.factory -> logger.syslog".
I have filecache, workspace, and scheduler enabled.
this issue solved this problem for me #3103620: Dependency on config storage causes circular reference in service container
This comment, https://www.drupal.org/project/drupal/issues/3103620#comment-15408346, redirected to this issue for a fix. I do not think it is a fx.
Comment #59
spokje#58: You might have c/p a wrong issue link (it is to this very issue) in there?
Comment #60
alexpott@SocialNicheGuru we're going to need some more information about how to reproduce what you are seeing. I have installed:
I can create the datetime.formatter and workspaces.manager services just fine after this. But my datetime.formatter does not depend on workspaces.manager - how is that happening on your install?
This MR is definitely resolving a bug.
Comment #61
catchOne question on the MR.
Comment #62
kim.pepperComment #63
alexpott@catch's feedback has been addressed. This looks good to go now. Thanks @kim.pepper.
Comment #64
catchCommitted/pushed to 11.x and cherry-picked to 10.3.x, thanks!
Comment #68
mfbBy the way, I noticed that at least one contrib file system decorator (s3fs) still has a dependency on logger. And logging seems even more useful/necessary for s3fs than the default local file_system (all kinds of API errors, network errors, etc.). So I still see some utility in the alternative work-around of a lazy config service that loggers could depend on (#3103620: Dependency on config storage causes circular reference in service container)