nextcloud/server · error · InvalidArgumentException

The calendar <{$calendar['uri']}> is already shared to user

Error message

The calendar <{$calendar['uri']}> is already shared to user <$userDestination>.You may use -f to move the calendar while deleting this share.

What it means

Thrown from checkShares() in occ dav:move-calendar when the calendar is already shared directly with the destination user (share href matches the destination uid). Moving it would create a self-share / duplicate access. With -f the direct share is removed via updateShares() before the move; without it the command aborts with this message (note the missing space after the period in the thrown text).

Source

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

			 * Check that user destination is member of the groups which whom the calendar was shared
			 * If we ask to force the migration, the share with the group is dropped
			 */
			if ($this->shareManager->shareWithGroupMembersOnly() === true && $prefix === 'groups' && !$this->groupManager->isInGroup($userDestination, $userOrGroup)) {
				if ($force) {
					$this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config, $this->logger), [], ['principal:principals/groups/' . $userOrGroup]);
				} else {
					throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$userOrGroup> with whom the calendar <" . $calendar['uri'] . '> was shared. You may use -f to move the calendar while deleting this share.');
				}
			}

			/**
			 * Check that calendar isn't already shared with user destination
			 */
			if ($userOrGroup === $userDestination) {
				if ($force) {
					$this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config, $this->logger), [], ['principal:principals/users/' . $userOrGroup]);
				} else {
					throw new \InvalidArgumentException('The calendar <' . $calendar['uri'] . "> is already shared to user <$userDestination>.You may use -f to move the calendar while deleting this share.");
				}
			}
		}

		return count($shares) > 0;
	}
}

View on GitHub (pinned to ecdeb153ff)

Solutions

  1. Re-run with --force to drop the now-redundant direct share and complete the move
  2. Or unshare first via the calendar UI / dav share endpoints, then re-run without -f
  3. After the move, confirm the destination user sees exactly one copy of the calendar
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
src="$1"; dst="$2"; name="$3"
# if the calendar is already shared with dst, plan for --force or unshare first
occ dav:list-calendar-shares "$dst" | grep -F "$name" && echo "Note: '$name' appears already shared with $dst" >&2

Prevention

When it happens

Trigger: `occ dav:move-calendar <src> <dst> <name>` where the source calendar was already shared with <dst> — typical when consolidating accounts that already collaborated.

Common situations: Offboarding moves where the departing user's calendar had been shared with the successor; migration dry-runs after shares were set up manually.

Related errors


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