nextcloud/server · error · InvalidArgumentException

User <$userDestination> already has a calendar named <$name>

Error message

User <$userDestination> already has a calendar named <$name>.

What it means

Thrown by occ dav:move-calendar when the destination user already owns a calendar with the same URI and --force was not given. It is the non-forced branch of the conflict check; with --force the command instead auto-renames the incoming calendar to <name>-N. Aborted before any share checks or the actual move, so state is unchanged.

Source

Thrown at apps/dav/lib/Command/MoveCalendar.php:94

		$calendar = $this->calDav->getCalendarByUri(self::URI_USERS . $userOrigin, $name);

		if ($calendar === null) {
			throw new \InvalidArgumentException("User <$userOrigin> has no calendar named <$name>. You can run occ dav:list-calendars to list calendars URIs for this user.");
		}

		// Calendar already exists
		if ($this->calendarExists($userDestination, $name)) {
			if ($input->getOption('force')) {
				// Try to find a suitable name
				$newName = $this->getNewCalendarName($userDestination, $name);

				// If we didn't find a suitable value after all the iterations, give up
				if ($this->calendarExists($userDestination, $newName)) {
					throw new \InvalidArgumentException("Unable to find a suitable calendar name for <$userDestination> with initial name <$name>.");
				}
			} else {
				throw new \InvalidArgumentException("User <$userDestination> already has a calendar named <$name>.");
			}
		}

		$hadShares = $this->checkShares($calendar, $userOrigin, $userDestination, $input->getOption('force'));
		if ($hadShares) {
			/**
			 * Warn that share links have changed if there are shares
			 */
			$this->io->note([
				'Please note that moving calendar ' . $calendar['uri'] . " from user <$userOrigin> to <$userDestination> has caused share links to change.",
				'Sharees will need to change "example.com/remote.php/dav/calendars/uid/' . $calendar['uri'] . "_shared_by_$userOrigin\" to \"example.com/remote.php/dav/calendars/uid/" . $newName ?: $calendar['uri'] . "_shared_by_$userDestination\""
			]);
		}

		$this->calDav->moveCalendar($name, self::URI_USERS . $userOrigin, self::URI_USERS . $userDestination, $newName);

		$this->io->success("Calendar <$name> was moved from user <$userOrigin> to <$userDestination>" . ($newName ? " as <$newName>" : ''));
		return self::SUCCESS;

View on GitHub (pinned to ecdeb153ff)

Solutions

  1. Add --force to let the moved calendar be renamed automatically (<name>-1 etc.) and keep both
  2. Or first delete/rename the destination calendar (`occ dav:delete-calendar <dst> <name>`) if it should be replaced, then re-run without -f
  3. Check `occ dav:list-calendars <destinationuid>` beforehand to decide which option fits

Example fix

# before
occ dav:move-calendar alice bob personal
# User <bob> already has a calendar named <personal>.

# after: keep both, incoming becomes personal-1
occ dav:move-calendar alice bob personal --force
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
src="$1"; dst="$2"; name="$3"; force="${4:-}"
if [ -z "$force" ] && occ dav:list-calendars "$dst" | awk 'NR>1 {print $1}' | grep -Fxq "$name"; then
  echo "Destination already has '$name' — pass --force or remove it first" >&2; exit 1
fi
occ dav:move-calendar "$src" "$dst" "$name" $force

Prevention

When it happens

Trigger: `occ dav:move-calendar <src> <dst> <name>` without -f while calendarExists(dst, name) is true, e.g. both users have a calendar URI 'personal'.

Common situations: Merging two accounts that both have default-like calendar URIs (personal, work); repeated migration attempts after earlier partial runs.

Related errors


AI-assisted analysis of nextcloud/server@ecdeb153ff (2026-08-17). Data as JSON: /api/errors/492581182a63809b. Report an issue: GitHub.