calcom/cal.diy · error · InternalServerErrorException
An unexpected error occurred while deleting the selected cal
Error message
An unexpected error occurred while deleting the selected calendar
What it means
InternalServerErrorException (HTTP 500) thrown as the final fallback when the caught value during selected-calendar deletion is NOT an Error instance (the `if (error instanceof Error)` branch was skipped). This handles non-Error throws such as strings, numbers, null, or plain objects thrown by a dependency, about which nothing is known beyond 'something unexpected happened'.
Source
Thrown at apps/api/v2/src/modules/selected-calendars/services/selected-calendars.service.ts:65
const removedCalendarEntry = await this.selectedCalendarsRepository.removeUserSelectedCalendar(
user.id,
integration,
externalId,
undefined
);
await this.calendarsCacheService.deleteConnectedAndDestinationCalendarsCache(user.id);
return removedCalendarEntry;
} catch (error) {
if (error instanceof Error) {
if (error.message === NO_SELECTED_CALENDAR_FOUND) {
throw new NotFoundException(NO_SELECTED_CALENDAR_FOUND);
} else if (error.message === MULTIPLE_SELECTED_CALENDARS_FOUND) {
throw new BadRequestException(MULTIPLE_SELECTED_CALENDARS_FOUND);
} else {
throw new InternalServerErrorException(error.message);
}
}
throw new InternalServerErrorException(
"An unexpected error occurred while deleting the selected calendar"
);
}
}
}
View on GitHub (pinned to 176037d0af)
Solutions
- Server-side, wrap the repository/cache calls so they always reject with proper Error instances (normalize `throw x` to `throw new Error(String(x))`).
- Check server logs for the original non-Error value to locate the misbehaving dependency.
- Add an outer exception filter that logs the raw thrown value for diagnostics before it becomes this generic 500.
Example fix
// before — non-Error throws become an opaque 500 throw new InternalServerErrorException( "An unexpected error occurred while deleting the selected calendar" ); // after — normalize at the source so the catch always sees an Error // in repository: if (!result) throw new Error(NO_SELECTED_CALENDAR_FOUND); // never: throw 'something';
Defensive patterns
Strategy: try-catch
Type guard
const isProperError = (e: unknown): e is Error => e instanceof Error;
Try / catch
try { await api.delete(`/selected-calendars/${integration}/${externalId}`); }
catch (e) {
if (e.status === 500 && /unexpected error occurred/i.test(e.message)) { /* log raw cause, alert ops */ }
throw e;
} Prevention
- Ensure all dependencies throw Error instances, not strings/objects.
- Add a global exception filter that normalizes non-Error throws and logs the raw value.
- Unit test the deletion path against synthetic non-Error rejections.
When it happens
Trigger: A dependency throws a non-Error value (e.g. `throw 'string'`), Prisma rejects with a non-Error rejection in some edge case, or a third-party library rejects with a plain object; the cache service throwing a string error would also land here.
Common situations: A library that throws strings instead of Error objects; an unhandled rejection propagated through async boundaries; a defensive `throw null` somewhere in the call chain; runtime type confusion after a refactor.
Related errors
- ${error.message}
- Could not set ${app} as default conferencing app
- No SelectedCalendar found.
- Multiple SelecteCalendars found. Skipping deletion
- CustomThrottlerGuard - Too many requests. Please try again l
AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12).
Data as JSON: /api/errors/7c58b4f36571f06a.
Report an issue: GitHub.