nextcloud/server · error · InvalidArgumentException

Calendar <$calendarId> not found.

Error message

Calendar <$calendarId> not found.

What it means

InvalidArgumentException thrown by occ dav:export-calendar (apps/dav/lib/Command/ExportCalendar.php:66) when ICalendarManager::getCalendarsForPrincipal('principals/users/<uid>', [<uri>]) returns an empty array - no calendar with that URI is registered for that principal.

Source

Thrown at apps/dav/lib/Command/ExportCalendar.php:66

			->addArgument('uri', InputArgument::REQUIRED, 'URI of calendar')
			->addOption('format', null, InputOption::VALUE_REQUIRED, 'Format of output (ical, jcal, xcal) defaults to ical', 'ical')
			->addOption('location', null, InputOption::VALUE_REQUIRED, 'Location of where to write the output. Defaults to stdout');
	}

	#[\Override]
	protected function execute(InputInterface $input, OutputInterface $output): int {
		$userId = $input->getArgument('uid');
		$calendarId = $input->getArgument('uri');
		$format = $input->getOption('format');
		$location = $input->getOption('location');

		if (!$this->userManager->userExists($userId)) {
			throw new InvalidArgumentException("User <$userId> not found.");
		}
		// retrieve calendar and evaluate if export is supported
		$calendars = $this->calendarManager->getCalendarsForPrincipal('principals/users/' . $userId, [$calendarId]);
		if ($calendars === []) {
			throw new InvalidArgumentException("Calendar <$calendarId> not found.");
		}
		$calendar = $calendars[0];
		if (!$calendar instanceof ICalendarExport) {
			throw new InvalidArgumentException("Calendar <$calendarId> does not support exporting");
		}
		// construct options object
		$options = new CalendarExportOptions();
		// evaluate if provided format is supported
		if (!in_array($format, ExportService::FORMATS, true)) {
			throw new InvalidArgumentException("Format <$format> is not valid.");
		}
		$options->setFormat($format);
		// evaluate if a valid location was given and is usable otherwise output to stdout
		if ($location !== null) {
			$handle = fopen($location, 'wb');
			if ($handle === false) {
				throw new InvalidArgumentException("Location <$location> is not valid. Cannot open location for write operation.");
			}

View on GitHub (pinned to ecdeb153ff)

Solutions

  1. Find the exact URI: PROPFIND /remote.php/dav/calendars/alice/ or query oc_calendars (uri column) for principaluri 'principals/users/alice'
  2. Share/delegation calendars are not under the target principal - export them from the owning user
  3. Re-run with the exact, case-sensitive URI

Example fix

# discover real uris
curl -u alice:*** -X PROPFIND https://host/remote.php/dav/calendars/alice/ | grep -oP '(?<=<d:href>)[^<]+'
# then
occ dav:export-calendar alice personal
Defensive patterns

Strategy: validation

Validate before calling

// resolve the uri via the CalDAV home before exporting
$calendars = $calendarManager->getCalendarsForPrincipal(
    'principals/users/' . $uid
);
$uris = array_map(fn ($c) => $c->getUri(), $calendars);
if (!in_array($calendarUri, $uris, true)) {
    throw new RuntimeException("Unknown calendar uri. Available: " . implode(', ', $uris));
}

Try / catch

try { /* run export */ }
catch (\InvalidArgumentException $e) {
    if (str_contains($e->getMessage(), 'not found')) { /* re-resolve uri via PROPFIND */ }
}

Prevention

When it happens

Trigger: occ dav:export-calendar alice <uri> where <uri> does not match any calendar URI (case-sensitive), the calendar belongs to another principal, is a deleted/calendar objects row with deleted flag, or is an app-provided calendar not resolved for that principal id.

Common situations: Using the display name ('Personal') instead of the URI ('personal'); calendars owned by a delegation/share rather than the principal; scheduled-deleted calendars after occ dav:cleanup; typos in case.

Related errors


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