{"record":{"id":"d556b2105746dd3a","repo":"nextcloud/server","slug":"error-importing-calendar-data-uid-uid-error","errorCode":null,"errorMessage":"Error importing calendar data: UID <$uid> - $errorMessage","messagePattern":"Error importing calendar data: UID <\\$uid> - \\$errorMessage","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"apps/dav/lib/CalDAV/Import/ImportService.php","lineNumber":374,"sourceCode":"\t\t\t\t\t\t\t$calendarId,\n\t\t\t\t\t\t\t$oid,\n\t\t\t\t\t\t\t$objectData\n\t\t\t\t\t\t);\n\t\t\t\t\t\tyield new ImportObjectEvent(\n\t\t\t\t\t\t\tdisposition: ImportDisposition::Updated,\n\t\t\t\t\t\t\tidentifier: $uid,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tyield new ImportObjectEvent(\n\t\t\t\t\t\t\tdisposition: ImportDisposition::Exists,\n\t\t\t\t\t\t\tidentifier: $uid,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (Exception $e) {\n\t\t\t\t$errorMessage = $e->getMessage();\n\t\t\t\tif ($options->getErrors() === $options::ERROR_FAIL) {\n\t\t\t\t\tthrow new Exception('Error importing calendar data: UID <' . $uid . '> - ' . $errorMessage, 0, $e);\n\t\t\t\t}\n\t\t\t\tyield new ImportObjectEvent(\n\t\t\t\t\tdisposition: ImportDisposition::Error,\n\t\t\t\t\tidentifier: $uid,\n\t\t\t\t\terrors: [$errorMessage]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Validate a component\n\t *\n\t * @param VCalendar $vObject\n\t * @param bool $repair attempt to repair the component\n\t * @param int $level minimum level of issues to return\n\t * @return list<mixed>\n\t */","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/CalDAV/Import/ImportService.php#L356-L392","documentation":"Wraps any exception raised by the CalDavBackend while creating or updating the calendar object for a UID (createCalendarObject / updateCalendarObject) during import. ImportService catches it, and when the error mode is ERROR_FAIL rethrows it prefixed with 'Error importing calendar data: UID <uid> -' keeping the original exception as previous. In non-failing mode the message is yielded in an Error ImportObjectEvent instead.","triggerScenarios":"A backend/DB failure during import: database unreachable or lock timeout, constraint violation on the object URI, serialized data rejected by storage, or another low-level CalDavBackend error while options->getErrors() === CalendarImportOptions::ERROR_FAIL.","commonSituations":"Importing large files that exhaust DB connection limits or transaction time; concurrent writes to the same calendar (duplicate URI race); MariaDB/MySQL row-size limits on large calendar objects; storage quota errors.","solutions":["Inspect the chained exception via getPrevious() (and your Nextcloud log) to find the real backend error before acting","For duplicate/URI races, re-run the import; the getCalendarObjectByUID() lookup makes re-imports idempotent per UID","Split very large imports into smaller batches and check DB health (max_allowed_packet, locks, disk space)"],"exampleFix":"// before\ntry {\n    foreach ($service->import($source, $calendar, $options) as $event) {}\n} catch (\\Exception $e) {\n    die($e->getMessage()); // only sees the wrapper\n}\n\n// after\ntry {\n    foreach ($service->import($source, $calendar, $options) as $event) {}\n} catch (\\Exception $e) {\n    $root = $e->getPrevious() ?? $e;\n    $this->logger->error('Import failed for UID: ' . $root->getMessage());\n}","handlingStrategy":"try-catch","validationCode":"// nothing caller-side prevents a backend fault; check calendar writability beforehand:\nif ($calendar->isReadOnly()) {\n    throw new RuntimeException('calendar is read-only');\n}","typeGuard":null,"tryCatchPattern":"try {\n    foreach ($service->import($source, $calendar, $options) as $event) {}\n} catch (\\Exception $e) {\n    $root = $e->getPrevious() ?? $e; // real backend error\n    $this->logger->error('calendar import failed', ['exception' => $root]);\n    // transient DB/lock issues: safe to retry; the per-UID upsert makes it idempotent\n}","preventionTips":["Always unwrap getPrevious() to diagnose the actual backend failure","Batch large imports and keep transactions short to avoid lock timeouts","Monitor Nextcloud server logs (data/nextcloud.log) alongside the exception"],"tags":["caldav","import","nextcloud","backend","database","php"],"backgroundTag":"calendar-backend-write-failure","analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}