nextcloud/server · error · InvalidArgumentException

Location <$location> is not valid. Cannot open location for

Error message

Location <$location> is not valid. Cannot open location for read operation.

What it means

InvalidArgumentException thrown by occ dav:import-calendar (apps/dav/lib/Command/ImportCalendar.php:112) when fopen($location, 'r') fails - the input file argument cannot be opened for reading. Happens for missing files, unreadable permissions, wrong path, or open_basedir restrictions.

Source

Thrown at apps/dav/lib/Command/ImportCalendar.php:112

		if ($calendar->isDeleted()) {
			throw new InvalidArgumentException("Calendar <$calendarId> is deleted");
		}
		// construct options object
		$options = new CalendarImportOptions();
		$options->setSupersede($supersede);
		if ($errors !== null) {
			$options->setErrors($errors);
		}
		if ($validation !== null) {
			$options->setValidate($validation);
		}
		$options->setFormat($format);
		$options->setCounts(true);
		// evaluate if a valid location was given and is usable otherwise default to stdin
		if ($location !== null) {
			$stream = fopen($location, 'r');
			if ($stream === false) {
				throw new InvalidArgumentException("Location <$location> is not valid. Cannot open location for read operation.");
			}
		} else {
			$stdin = fopen('php://stdin', 'r');
			if ($stdin === false) {
				throw new InvalidArgumentException('Cannot open stdin for read operation.');
			}
			$tempPath = $this->tempManager->getTemporaryFile();
			$stream = fopen($tempPath, 'w+');
			while (!feof($stdin)) {
				fwrite($stream, fread($stdin, 8192));
			}
			fclose($stdin);
			fseek($stream, 0);
		}
		$timeStarted = microtime(true);
		$totalCreated = 0;
		$totalUpdated = 0;
		$totalSkipped = 0;

View on GitHub (pinned to ecdeb153ff)

Solutions

  1. Use an absolute path and verify it exists: ls -l /abs/path/calendar.ics
  2. chmod a+r (or chown www-data) so the occ user can read it
  3. Omit the location argument and pipe stdin instead: cat calendar.ics | occ dav:import-calendar alice personal

Example fix

# before
occ dav:import-calendar alice personal cal.ics        # run from wrong cwd
# after
occ dav:import-calendar alice personal /home/alice/cal.ics
# or stream via stdin
cat /home/alice/cal.ics | occ dav:import-calendar alice personal
Defensive patterns

Strategy: validation

Validate before calling

// shell: verify the input file before occ
if (!is_file($path) || !is_readable($path)) {
    throw new RuntimeException("Cannot read $path");
}

Prevention

When it happens

Trigger: occ dav:import-calendar alice personal /path/to/calendar.ics where the file does not exist relative to the occ process cwd, is not readable by the occ user (www-data), or lies outside open_basedir.

Common situations: Relative paths resolved from the web root instead of the shell cwd; file uploaded as root and not readable by www-data; typos; running occ in a container without the mounted file.

Related errors


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