Merge pull request #50763 from nextcloud/backport/50498/stable31

[stable31] Don't rethrow a type error
This commit is contained in:
Andy Scherzinger 2025-02-11 20:31:50 +01:00 committed by GitHub
commit 2a76114134
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 28 deletions

View file

@ -111,11 +111,11 @@ class Directory extends Node implements \Sabre\DAV\ICollection, \Sabre\DAV\IQuot
// only allow 1 process to upload a file at once but still allow reading the file while writing the part file
$node->acquireLock(ILockingProvider::LOCK_SHARED);
$this->fileView->lockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
$this->fileView->lockFile($this->path . '/' . $name . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
$result = $node->put($data);
$this->fileView->unlockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
$this->fileView->unlockFile($this->path . '/' . $name . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
$node->releaseLock(ILockingProvider::LOCK_SHARED);
return $result;
} catch (StorageNotAvailableException $e) {

View file

@ -9,6 +9,7 @@ namespace OCA\DAV\Connector\Sabre;
use Sabre\DAV\Exception;
use Sabre\DAV\Version;
use TypeError;
/**
* Class \OCA\DAV\Connector\Sabre\Server
@ -47,20 +48,17 @@ class Server extends \Sabre\DAV\Server {
$this->httpRequest->setBaseUrl($this->getBaseUri());
$this->invokeMethod($this->httpRequest, $this->httpResponse);
} catch (\Throwable $e) {
if ($e instanceof \TypeError) {
try {
$this->emit('exception', [$e]);
} catch (\Exception) {
}
if ($e instanceof TypeError) {
/*
* The TypeError includes the file path where the error occurred,
* potentially revealing the installation directory.
*
* By re-throwing the exception, we ensure that the
* default exception handler processes it.
*/
throw $e;
}
try {
$this->emit('exception', [$e]);
} catch (\Exception $ignore) {
$e = new TypeError('A type error occurred. For more details, please refer to the logs, which provide additional context about the type error.');
}
$DOM = new \DOMDocument('1.0', 'utf-8');

View file

@ -2062,9 +2062,9 @@ class View {
);
}
} catch (LockedException $e) {
// rethrow with the a human-readable path
// rethrow with the human-readable path
throw new LockedException(
$this->getPathRelativeToFiles($absolutePath),
$path,
$e,
$e->getExistingLock()
);
@ -2102,20 +2102,12 @@ class View {
);
}
} catch (LockedException $e) {
try {
// rethrow with the a human-readable path
throw new LockedException(
$this->getPathRelativeToFiles($absolutePath),
$e,
$e->getExistingLock()
);
} catch (\InvalidArgumentException $ex) {
throw new LockedException(
$absolutePath,
$ex,
$e->getExistingLock()
);
}
// rethrow with the a human-readable path
throw new LockedException(
$path,
$e,
$e->getExistingLock()
);
}
return true;