nextcloud/server · warning · InvalidArgumentException

Format <$format> is not valid.

Error message

Format <$format> is not valid.

What it means

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.

Source

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

		$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.");
			}

			foreach ($this->exportService->export($calendar, $options) as $chunk) {
				fwrite($handle, $chunk);
			}
			fclose($handle);
		} else {
			foreach ($this->exportService->export($calendar, $options) as $chunk) {
				$output->writeln($chunk);
			}
		}

View on GitHub (pinned to ecdeb153ff)

Solutions

  1. Use one of ical (default), jcal, or xcal
  2. Write the desired extension via --location (e.g. --location=/tmp/out.ics) and leave --format as ical

Example fix

# before
occ dav:export-calendar alice personal --format=ics
# after
occ dav:export-calendar alice personal --format=ical --location=/tmp/calendar.ics
Defensive patterns

Strategy: validation

Validate before calling

// keep the allowed set in one place for scripts
const FORMATS = ['ical', 'jcal', 'xcal'];
if (!FORMATS.includes(format)) {
    throw new Error(`--format must be one of: ${FORMATS.join(', ')}`);
}

Type guard

const isExportFormat = (f: string): f is 'ical'|'jcal'|'xcal' =>
    ['ical','jcal','xcal'].includes(f);

Prevention

When it happens

Trigger: 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.

Common situations: Passing the file extension '.ics' instead of the format name; assuming JSON output; scripts written against other tools that accept different format tokens.

Related errors


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