{"record":{"id":"39330df1d49620ff","repo":"nextcloud/server","slug":"calendar-calendarid-not-found","errorCode":null,"errorMessage":"Calendar <$calendarId> not found.","messagePattern":"Calendar <\\$calendarId> not found\\.","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"apps/dav/lib/Command/ExportCalendar.php","lineNumber":66,"sourceCode":"\t\t\t->addArgument('uri', InputArgument::REQUIRED, 'URI of calendar')\n\t\t\t->addOption('format', null, InputOption::VALUE_REQUIRED, 'Format of output (ical, jcal, xcal) defaults to ical', 'ical')\n\t\t\t->addOption('location', null, InputOption::VALUE_REQUIRED, 'Location of where to write the output. Defaults to stdout');\n\t}\n\n\t#[\\Override]\n\tprotected function execute(InputInterface $input, OutputInterface $output): int {\n\t\t$userId = $input->getArgument('uid');\n\t\t$calendarId = $input->getArgument('uri');\n\t\t$format = $input->getOption('format');\n\t\t$location = $input->getOption('location');\n\n\t\tif (!$this->userManager->userExists($userId)) {\n\t\t\tthrow new InvalidArgumentException(\"User <$userId> not found.\");\n\t\t}\n\t\t// retrieve calendar and evaluate if export is supported\n\t\t$calendars = $this->calendarManager->getCalendarsForPrincipal('principals/users/' . $userId, [$calendarId]);\n\t\tif ($calendars === []) {\n\t\t\tthrow new InvalidArgumentException(\"Calendar <$calendarId> not found.\");\n\t\t}\n\t\t$calendar = $calendars[0];\n\t\tif (!$calendar instanceof ICalendarExport) {\n\t\t\tthrow new InvalidArgumentException(\"Calendar <$calendarId> does not support exporting\");\n\t\t}\n\t\t// construct options object\n\t\t$options = new CalendarExportOptions();\n\t\t// evaluate if provided format is supported\n\t\tif (!in_array($format, ExportService::FORMATS, true)) {\n\t\t\tthrow new InvalidArgumentException(\"Format <$format> is not valid.\");\n\t\t}\n\t\t$options->setFormat($format);\n\t\t// evaluate if a valid location was given and is usable otherwise output to stdout\n\t\tif ($location !== null) {\n\t\t\t$handle = fopen($location, 'wb');\n\t\t\tif ($handle === false) {\n\t\t\t\tthrow new InvalidArgumentException(\"Location <$location> is not valid. Cannot open location for write operation.\");\n\t\t\t}","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/Command/ExportCalendar.php#L48-L84","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Find the exact URI: PROPFIND /remote.php/dav/calendars/alice/ or query oc_calendars (uri column) for principaluri 'principals/users/alice'","Share/delegation calendars are not under the target principal - export them from the owning user","Re-run with the exact, case-sensitive URI"],"exampleFix":"# discover real uris\ncurl -u alice:*** -X PROPFIND https://host/remote.php/dav/calendars/alice/ | grep -oP '(?<=<d:href>)[^<]+'\n# then\nocc dav:export-calendar alice personal","handlingStrategy":"validation","validationCode":"// resolve the uri via the CalDAV home before exporting\n$calendars = $calendarManager->getCalendarsForPrincipal(\n    'principals/users/' . $uid\n);\n$uris = array_map(fn ($c) => $c->getUri(), $calendars);\nif (!in_array($calendarUri, $uris, true)) {\n    throw new RuntimeException(\"Unknown calendar uri. Available: \" . implode(', ', $uris));\n}","typeGuard":null,"tryCatchPattern":"try { /* run export */ }\ncatch (\\InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'not found')) { /* re-resolve uri via PROPFIND */ }\n}","preventionTips":["Always PROPFIND the calendar home to get exact URIs","URIs are case-sensitive; never substitute display names","Script against oc_calendars.uri when DB access is available"],"tags":["occ","cli","export","calendar","caldav","not-found","invalid-argument"],"backgroundTag":"resource-not-found","analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}