Breaking: #105920 - Folder->getSubFolder() throws FolderDoesNotExistException
See forge#105920
Description
An exception handling detail within the File Abstraction Layer (FAL) resource
handling has been changed. When calling
get on a
Folder object, and if this subfolder does
not exist, the specific
\TYPO3\ is
now raised instead of the global
\Invalid.
Impact
The change may affect extensions that directly or indirectly call
Folder->get and expect a
\Invalid to
be thrown.
Affected installations
Folder does not extend
\Invalid. Code that currently expects a
\Invalid to be thrown needs to be adapted.
Migration
The change is breaking for code that takes an "optimistic" approach like: "get the subfolder object, and if this throws, create one". Example:
try {
$mySubFolder = $myFolder->getSubFolder('mySubFolder');
} catch (\InvalidArgumentException) {
$mySubFolder = $myFolder->createFolder('mySubFolder');
}
This should be changed to catch a
Folder
instead:
use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
try {
$mySubFolder = $myFolder->getSubFolder('mySubFolder');
} catch (FolderDoesNotExistException) {
$mySubFolder = $myFolder->createFolder('mySubFolder');
}
Extensions that need to stay compatible with both TYPO3 v13 and v14 should catch
both exceptions and should later avoid catching
\Invalid when v13 compatibility is dropped:
use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
try {
$mySubFolder = $myFolder->getSubFolder('mySubFolder');
} catch (\InvalidArgumentException|FolderDoesNotExistException) {
// @todo: Remove \InvalidArgumentException from catch list when
// TYPO3 v13 compatibility is dropped.
$mySubFolder = $myFolder->createFolder('mySubFolder');
}