Skip to content

Commit 90a1aea

Browse files
authored
Merge pull request #50498 from nextcloud/bug/48678/restore-dav-error-response-2
Don't rethrow a type error
2 parents 53749e0 + 4978cd3 commit 90a1aea

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

apps/dav/lib/Connector/Sabre/Directory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ public function createFile($name, $data = null) {
111111

112112
// only allow 1 process to upload a file at once but still allow reading the file while writing the part file
113113
$node->acquireLock(ILockingProvider::LOCK_SHARED);
114-
$this->fileView->lockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
114+
$this->fileView->lockFile($this->path . '/' . $name . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
115115

116116
$result = $node->put($data);
117117

118-
$this->fileView->unlockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
118+
$this->fileView->unlockFile($this->path . '/' . $name . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
119119
$node->releaseLock(ILockingProvider::LOCK_SHARED);
120120
return $result;
121121
} catch (StorageNotAvailableException $e) {

apps/dav/lib/Connector/Sabre/Server.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Sabre\DAV\Exception;
1111
use Sabre\DAV\Version;
12+
use TypeError;
1213

1314
/**
1415
* Class \OCA\DAV\Connector\Sabre\Server
@@ -47,20 +48,17 @@ public function start() {
4748
$this->httpRequest->setBaseUrl($this->getBaseUri());
4849
$this->invokeMethod($this->httpRequest, $this->httpResponse);
4950
} catch (\Throwable $e) {
50-
if ($e instanceof \TypeError) {
51+
try {
52+
$this->emit('exception', [$e]);
53+
} catch (\Exception) {
54+
}
55+
56+
if ($e instanceof TypeError) {
5157
/*
5258
* The TypeError includes the file path where the error occurred,
5359
* potentially revealing the installation directory.
54-
*
55-
* By re-throwing the exception, we ensure that the
56-
* default exception handler processes it.
5760
*/
58-
throw $e;
59-
}
60-
61-
try {
62-
$this->emit('exception', [$e]);
63-
} catch (\Exception $ignore) {
61+
$e = new TypeError('A type error occurred. For more details, please refer to the logs, which provide additional context about the type error.');
6462
}
6563

6664
$DOM = new \DOMDocument('1.0', 'utf-8');

lib/private/Files/View.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,9 +2062,9 @@ private function lockPath($path, $type, $lockMountPoint = false) {
20622062
);
20632063
}
20642064
} catch (LockedException $e) {
2065-
// rethrow with the a human-readable path
2065+
// rethrow with the human-readable path
20662066
throw new LockedException(
2067-
$this->getPathRelativeToFiles($absolutePath),
2067+
$path,
20682068
$e,
20692069
$e->getExistingLock()
20702070
);
@@ -2102,20 +2102,12 @@ public function changeLock($path, $type, $lockMountPoint = false) {
21022102
);
21032103
}
21042104
} catch (LockedException $e) {
2105-
try {
2106-
// rethrow with the a human-readable path
2107-
throw new LockedException(
2108-
$this->getPathRelativeToFiles($absolutePath),
2109-
$e,
2110-
$e->getExistingLock()
2111-
);
2112-
} catch (\InvalidArgumentException $ex) {
2113-
throw new LockedException(
2114-
$absolutePath,
2115-
$ex,
2116-
$e->getExistingLock()
2117-
);
2118-
}
2105+
// rethrow with the a human-readable path
2106+
throw new LockedException(
2107+
$path,
2108+
$e,
2109+
$e->getExistingLock()
2110+
);
21192111
}
21202112

21212113
return true;

0 commit comments

Comments
 (0)