Skip to content

Fix/delete selected calendar error propagation#29487

Open
SahilArate wants to merge 4 commits into
calcom:mainfrom
SahilArate:fix/delete-selected-calendar-error-propagation
Open

Fix/delete selected calendar error propagation#29487
SahilArate wants to merge 4 commits into
calcom:mainfrom
SahilArate:fix/delete-selected-calendar-error-propagation

Conversation

@SahilArate
Copy link
Copy Markdown

What does this PR do?

Fixes #29456

The catch block in deleteSelectedCalendar correctly handled two known errors (NO_SELECTED_CALENDAR_FOUND, MULTIPLE_SELECTED_CALENDARS_FOUND) but silently swallowed all other unexpected errors, causing the function to implicitly return undefined on database failures or runtime errors. Callers had no way to detect the deletion had failed.
Fixed by throwing InternalServerErrorException for any unrecognized error, consistent with the NestJS HTTP exception pattern already used in this service (NotFoundException, BadRequestException). Also handles the edge case where the thrown value is not an Error instance.

Visual Demo

Image Demo:

Before (Buggy):
DB crash → catch block → no matching error message → silent undefined returned ❌
Caller has no idea the deletion failed
After (Fixed):
DB crash → catch block → no matching error message → InternalServerErrorException thrown ✅
Caller receives HTTP 500 with a clear error message
Code change:
typescript// BEFORE — falls off silently
} 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);
}
}
// ❌ returns undefined silently here
}

// AFTER — unexpected errors propagate correctly
} 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);
}
}
// ✅ Re-throw unexpected errors so callers are aware the deletion failed
throw new InternalServerErrorException(
error instanceof Error
? error.message
: "An unexpected error occurred while deleting the selected calendar"
);
}
Mandatory Tasks (DO NOT REMOVE)

I have self-reviewed the code.
N/A — no documentation change required for this bug fix.
I confirm automated tests are in place that prove my fix is effective.

How should this be tested?

No special environment variables needed
Need a valid user with at least one connected calendar credential
To reproduce the bug: mock removeUserSelectedCalendar to throw new Error("DB_CONNECTION_FAILED") — before fix it returns undefined silently, after fix it throws 500 InternalServerErrorException
Happy path (unchanged): calendar not found → 404, multiple found → 400, success → returns removed calendar entry

Checklist

I have read the contributing guide
My code follows the style guidelines of this project
I have commented my code where relevant
My changes generate no new warnings
My PR is small and focused — 1 file changed, 2 lines added

@github-actions
Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @SahilArate! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@github-actions
Copy link
Copy Markdown
Contributor

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "Fix/delete selected calendar error propagation". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@github-actions github-actions Bot added the 🐛 bug Something isn't working label May 31, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8d33df85-cc78-4b53-8f1b-1d093d141a20

📥 Commits

Reviewing files that changed from the base of the PR and between 180ede2 and ab9f763.

📒 Files selected for processing (4)
  • apps/api/v2/src/modules/selected-calendars/services/selected-calendars.service.ts
  • packages/app-store/redirect-apps.generated.ts
  • packages/embeds/embed-core/src/embed-iframe.ts
  • packages/embeds/embed-core/src/embed.ts

📝 Walkthrough

Walkthrough

This PR hardens the security of parent-child iframe communication in the embed SDK by implementing origin validation, refactors embed state management hooks to prevent unintended re-renders, filters reserved parameters from query forwarding in modal routing, and improves error handling in the calendar service. The changes reorganize code structure across the embed iframe and embed client files while maintaining existing functionality, with security-critical updates to message validation in both directions (iframe-to-parent and parent-to-iframe postMessage calls).

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The raw summary shows changes to three files (selected-calendars.service.ts, redirect-apps.generated.ts, embed-iframe.ts, embed.ts), but issue #29456 only requires changes to selected-calendars.service.ts. The additional changes to unrelated files appear to exceed the stated PR scope and linked issue requirements. Remove the out-of-scope changes to redirect-apps.generated.ts, embed-iframe.ts, and embed.ts. The PR should focus solely on fixing deleteSelectedCalendar error propagation as specified in issue #29456.
Out of Scope Changes check ⚠️ Warning The raw summary reveals changes to four files total: selected-calendars.service.ts (in-scope), but also redirect-apps.generated.ts, embed-iframe.ts, and embed.ts which are not mentioned in issue #29456 or PR objectives. These unrelated changes appear out-of-scope for a focused error-propagation fix. Remove changes to redirect-apps.generated.ts, embed-iframe.ts, and embed.ts. Focus the PR solely on the deleteSelectedCalendar error handling fix in selected-calendars.service.ts.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Fix/delete selected calendar error propagation' directly and clearly describes the main change: fixing error propagation in the deleteSelectedCalendar function.
Description check ✅ Passed The PR description is comprehensive and directly related to the changeset, explaining the bug fix with before/after code examples, testing instructions, and implementation details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix/delete-selected-calendar-error-propagation

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@millerc13
Copy link
Copy Markdown

looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LOW: deleteSelectedCalendar silently swallows unexpected errors

2 participants