moodle/moodle · error · repository_nextcloud\request_exception
couldnotmove
couldnotmove
Error message
couldnotmove
What it means
repository_nextcloud's get_file() flow throws this request_exception when, after creating a share between the system account and the user (OCS status 100), the WebDAV MOVE of the shared file into the controlled link folder returns a status other than 201 (created) or 412 (precondition failed, meaning target already exists). The language string 'couldnotmove' is interpolated with the configured controlled-link folder name. It signals that the file could not be relocated into the Moodle-managed Nextcloud folder.
Solutions
- Verify the Nextcloud issuer's webdav endpoint URL in Site admin > OAuth 2 services points to the correct remote.php/webdav path
- Log in to Nextcloud as the system account and confirm the controlled link folder exists and is writable, or delete/recreate it so create_storage_folder() rebuilds it
- Check the system OAuth client scopes include write access (PROPFIND/MOVE) and that the system account is not over quota
- Enable WebDAV/debug logging to capture the actual HTTP status from transfer_file_to_path and address that specific failure
- If the folder exists but is stale, run a cron/repository cache purge so the repository re-inits the WebDAV session
Example fix
// before (diagnostic wrap around repository internals is not possible, but pre-check the folder) $copyresult = $linkmanager->transfer_file_to_path($filetarget, $this->controlledlinkfoldername, 'move', $this->dav); // after: ensure folder exists and refresh DAV session before moving $linkmanager->create_storage_folder($this->controlledlinkfoldername, $this->dav); $this->initiate_webdavclient(); $copyresult = $linkmanager->transfer_file_to_path($filetarget, $this->controlledlinkfoldername, 'move', $this->dav);
Defensive patterns
Strategy: try-catch
Validate before calling
// before calling get_file, verify the controlled folder exists via the repository // (no public pre-check API; do a lightweight PROPFIND through admin tools) // curl -u <systemuser>:<token> -X PROPFIND https://cloud.example.com/remote.php/webdav/<ControlledLinkFolder>/
Try / catch
try {
$repo->get_file($reference, $filename, $contenthash, $pathname, $options);
} catch (\repository_nextcloud\request_exception $e) {
// inspect $e->errorInfo['errormessage']; check DAV endpoint + folder, then retry once
debugging($e->getMessage());
throw $e;
} Prevention
- Never delete or rename the controlled link folder in Nextcloud manually
- Keep the OAuth2 issuer's webdav endpoint URL correct after Nextcloud upgrades
- Monitor system-account quota and permission changes
- Pin compatible Nextcloud/Moodle repository plugin versions
When it happens
Trigger: OCS share creation succeeded (statuscode 100), but linkmanager->transfer_file_to_path(...,'move',$this->dav) returns e.g. 403/404/409/502 instead of 201 or 412: the WebDAV endpoint is wrong, the destination folder was deleted, quota is exhausted, or the WebDAV client lacks permission to move.
Common situations: Admin configured the issuer's webdav endpoint incorrectly; the controlled link folder (default ' Controlled Link Folder'-type name) was manually deleted in Nextcloud; system-account OAuth token lost write scope; Nextcloud version changed OCS/WebDAV behavior; disk quota exceeded for the system account.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- filenotaccessed
- invalidresponse
- notauthorized
- A contextlist has already been added for the
- A filter of type ' ' has already been added. Check that you…
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/4b3b1eddb3da17c5.
Report an issue: GitHub.
Appendix: source
Thrown at public/repository/nextcloud/lib.php:510
// 2. Check whether user has folder for files otherwise create it.
$linkmanager->create_storage_folder($this->controlledlinkfoldername, $this->dav);
$userinfo = $this->client->get_userinfo();
$username = $userinfo['username'];
// Creates a share between the systemaccount and the user.
$responsecreateshare = $linkmanager->create_share_user_sysaccount($reference->link, $username, $maywrite);
$statuscode = $responsecreateshare['statuscode'];
if ($statuscode == 403) {
$shareid = $linkmanager->get_shares_from_path($reference->link, $username);
} else if ($statuscode == 100) {
$filetarget = $linkmanager->get_share_information_from_shareid($responsecreateshare['shareid'], $username);
$copyresult = $linkmanager->transfer_file_to_path($filetarget, $this->controlledlinkfoldername,
'move', $this->dav);
if (!($copyresult == 201 || $copyresult == 412)) {
throw new \repository_nextcloud\request_exception(array('instance' => $repositoryname,
'errormessage' => get_string('couldnotmove', 'repository_nextcloud', $this->controlledlinkfoldername)));
}
$shareid = $responsecreateshare['shareid'];
} else if ($statuscode == 997) {
throw new \repository_nextcloud\request_exception(array('instance' => $repositoryname,
'errormessage' => get_string('notauthorized', 'repository_nextcloud')));
} else {
$details = get_string('filenotaccessed', 'repository_nextcloud');
throw new \repository_nextcloud\request_exception(array('instance' => $repositoryname, 'errormessage' => $details));
}
$filetarget = $linkmanager->get_share_information_from_shareid((int)$shareid, $username);
// Obtain the file from Nextcloud using a Bearer token authenticated connection because we cannot perform a redirect here.
// The reason is that Nextcloud uses samesite cookie validation, i.e. a redirected request would not be authenticated.
// (Also the browser might use the session of a Nextcloud user that is different from the one that is known to Moodle.)
$filename = basename($filetarget);
$tmppath = make_request_directory() . '/' . $filename;
$this->dav->open();View on GitHub (pinned to 48ea8c3322)