{"record":{"id":"8e8a3740c0c229e8","repo":"nextcloud/server","slug":"format-format-is-not-valid","errorCode":null,"errorMessage":"Format <$format> is not valid.","messagePattern":"Format <\\$format> is not valid\\.","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"warning","filePath":"apps/dav/lib/Command/ExportCalendar.php","lineNumber":76,"sourceCode":"\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}\n\n\t\t\tforeach ($this->exportService->export($calendar, $options) as $chunk) {\n\t\t\t\tfwrite($handle, $chunk);\n\t\t\t}\n\t\t\tfclose($handle);\n\t\t} else {\n\t\t\tforeach ($this->exportService->export($calendar, $options) as $chunk) {\n\t\t\t\t$output->writeln($chunk);\n\t\t\t}\n\t\t}","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/Command/ExportCalendar.php#L58-L94","documentation":"InvalidArgumentException thrown by occ dav:export-calendar (apps/dav/lib/Command/ExportCalendar.php:76) when --format is not one of ExportService::FORMATS = ['ical','jcal','xcal']. The list is checked strictly (in_array with strict comparison) against the lowercase canonical names.","triggerScenarios":"occ dav:export-calendar alice personal --format=ics (or ICal/iCal/json/csv) - anything outside ical, jcal, xcal is rejected. Default when omitted is ical.","commonSituations":"Passing the file extension '.ics' instead of the format name; assuming JSON output; scripts written against other tools that accept different format tokens.","solutions":["Use one of ical (default), jcal, or xcal","Write the desired extension via --location (e.g. --location=/tmp/out.ics) and leave --format as ical"],"exampleFix":"# before\nocc dav:export-calendar alice personal --format=ics\n# after\nocc dav:export-calendar alice personal --format=ical --location=/tmp/calendar.ics","handlingStrategy":"validation","validationCode":"// keep the allowed set in one place for scripts\nconst FORMATS = ['ical', 'jcal', 'xcal'];\nif (!FORMATS.includes(format)) {\n    throw new Error(`--format must be one of: ${FORMATS.join(', ')}`);\n}","typeGuard":"const isExportFormat = (f: string): f is 'ical'|'jcal'|'xcal' =>\n    ['ical','jcal','xcal'].includes(f);","tryCatchPattern":null,"preventionTips":["Default to ical and omit --format unless jCal/xCal is required","Never pass file extensions (.ics) as the format","Let --location control the output filename"],"tags":["occ","cli","export","calendar","invalid-format","argument-validation"],"backgroundTag":"unsupported-format-parameter","analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}