calcom/cal.diy · error · BadRequestException
Could not add this apple calendar account: ${reason}
Error message
Could not add this apple calendar account: ${reason} What it means
Thrown by AppleCalendarService.saveCalendarCredentials (apple-calendar.service.ts:134) as BadRequestException (HTTP 400) from a catch-all around BuildCalendarService + dav.listCalendars() + upsert. The caught error is stringified into the message via template literal (`${reason}`), which discards the original stack/cause and can leak internal detail. The '${reason}' segment usually contains the real underlying error text.
Source
Thrown at apps/api/v2/src/platform/calendars/services/apple-calendar.service.ts:134
process.env.CALENDSO_ENCRYPTION_KEY || ""
),
userId: userId,
teamId: null,
appId: APPLE_CALENDAR_ID,
invalid: false,
delegationCredentialId: null,
encryptedKey: null,
};
const dav = BuildCalendarService({
id: 0,
...data,
user: { email: userEmail },
});
await dav?.listCalendars();
await this.credentialRepository.upsertUserAppCredential(APPLE_CALENDAR_TYPE, data.key, userId);
} catch (reason) {
throw new BadRequestException(`Could not add this apple calendar account: ${reason}`);
}
return {
status: SUCCESS_STATUS,
};
}
}
View on GitHub (pinned to 176037d0af)
Solutions
- Read the text after 'Could not add this apple calendar account: ' in the 400 body — it carries the underlying error message.
- Verify process.env.CALENDSO_ENCRYPTION_KEY is set and identical across all instances (encryption key rotation breaks old credentials).
- Test the supplied credentials directly against Apple's CalDAV endpoint to isolate provider vs. app error.
- If reason mentions 'cannot read property' or null service, confirm the apple_calendar app is installed/registered in BuildCalendarService's registry.
Example fix
// before (service): swallows original error
} catch (reason) {
throw new BadRequestException(`Could not add this apple calendar account: ${reason}`);
}
// after: log stack and preserve cause for diagnosability
} catch (reason) {
this.logger?.error?.('apple save failed', reason);
throw new BadRequestException(`Could not add this apple calendar account: ${(reason as Error).message}`, { cause: reason });
} Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: ensure encryption key is set and credentials look valid
if (!process.env.CALENDSO_ENCRYPTION_KEY) {
throw new Error('CALENDSO_ENCRYPTION_KEY is not set — Apple save will fail.');
}
// Validate input before calling save (see error 364 validation) Type guard
function isEncryptionKeyConfigured() {
return typeof process.env.CALENDSO_ENCRYPTION_KEY === 'string'
&& process.env.CALENDSO_ENCRYPTION_KEY.length > 0;
} Try / catch
try {
await api.post('/v2/calendars/apple_calendar/save', { username, password });
} catch (e) {
const reason = e.response?.data?.message?.replace(/.*:\s*/, ''); // text after the colon
if (/encrypt|key/i.test(reason)) {
throw new ConfigError('CALENDSO_ENCRYPTION_KEY issue — contact admin');
}
if (/auth|credential|unauthorized/i.test(reason)) {
throw new UserError('Apple credentials are incorrect — re-enter them.');
}
throw e;
} Prevention
- Keep CALENDSO_ENCRYPTION_KEY identical across all instances and deploys; never rotate without re-encrypting existing credentials.
- Log the underlying reason server-side (it is currently only in the HTTP message).
- Test credentials against Apple's CalDAV endpoint directly during onboarding to fail fast.
When it happens
Trigger: Wrong Apple credentials causing DAV auth failure; CALENDSO_ENCRYPTION_KEY unset/mismatched so symmetricEncrypt/symmetricDecrypt misbehave; Apple CalDAV endpoint unreachable; BuildCalendarService returns a service whose listCalendars() rejects.
Common situations: Missing or rotated CALENDSO_ENCRYPTION_KEY env var across deploys; user supplied wrong app-specific password; network egress blocked to caldav.apple.com; apple_calendar app not registered so BuildCalendarService yields a failing service.
Related errors
- Credentials for apple calendar not found.
- Invalid apple calendar credentials.
- Username or password cannot be empty
- Event operations for this connection are currently only avai
- ${action} is currently only available for Google Calendar. O
AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12).
Data as JSON: /api/errors/faadafb4c608344e.
Report an issue: GitHub.