[8.x] Throw exception when unable to create LockableFile #36674
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We run into this cryptic error in our production Laravel servers:
This is because
LockableFile
incorrectly presumes that the result offopen
(which is stored in$this->handle
) is always a file pointer resource, when in fact it can be the boolean valuefalse
when the file failed to create properly - relevant docs. When the file fails to create,$this->handle
silently gets set to false here:framework/src/Illuminate/Filesystem/LockableFile.php
Lines 65 to 68 in 72ea328
...such that subsequent references to
$this->handle
will fail with the above cryptic message, when in fact the real error happened much earlier when the file was supposed to be created.If, instead, we throw an exception when
fopen
fails, the developer will see a helpful error showing the actual path of the file which failed to create, so that we can action upon that, whether it be updating the group permissions or umask of thestorage
folder or whatever is needed. This will be a much better developer experience then waiting for a subsequent usage of$this->handle
to fail cryptically.I'm not sure exactly what exception should be thrown here, please let me know how this can be improved.