{"record":{"id":"7c58b4f36571f06a","repo":"calcom/cal.diy","slug":"an-unexpected-error-occurred-while-deleting-the-se","errorCode":null,"errorMessage":"An unexpected error occurred while deleting the selected calendar","messagePattern":"An unexpected error occurred while deleting the selected calendar","errorType":"http","errorClass":"InternalServerErrorException","httpStatus":500,"severity":"error","filePath":"apps/api/v2/src/modules/selected-calendars/services/selected-calendars.service.ts","lineNumber":65,"sourceCode":"      const removedCalendarEntry = await this.selectedCalendarsRepository.removeUserSelectedCalendar(\n        user.id,\n        integration,\n        externalId,\n        undefined\n      );\n      await this.calendarsCacheService.deleteConnectedAndDestinationCalendarsCache(user.id);\n      return removedCalendarEntry;\n    } catch (error) {\n      if (error instanceof Error) {\n        if (error.message === NO_SELECTED_CALENDAR_FOUND) {\n          throw new NotFoundException(NO_SELECTED_CALENDAR_FOUND);\n        } else if (error.message === MULTIPLE_SELECTED_CALENDARS_FOUND) {\n          throw new BadRequestException(MULTIPLE_SELECTED_CALENDARS_FOUND);\n        } else {\n          throw new InternalServerErrorException(error.message);\n        }\n      }\n      throw new InternalServerErrorException(\n        \"An unexpected error occurred while deleting the selected calendar\"\n      );\n    }\n  }\n}\n","sourceCodeStart":47,"sourceCodeEnd":71,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/modules/selected-calendars/services/selected-calendars.service.ts#L47-L71","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — non-Error throws become an opaque 500\nthrow new InternalServerErrorException(\n  \"An unexpected error occurred while deleting the selected calendar\"\n);\n// after — normalize at the source so the catch always sees an Error\n// in repository:\nif (!result) throw new Error(NO_SELECTED_CALENDAR_FOUND);\n// never: throw 'something';","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isProperError = (e: unknown): e is Error => e instanceof Error;","tryCatchPattern":"try { await api.delete(`/selected-calendars/${integration}/${externalId}`); }\ncatch (e) {\n  if (e.status === 500 && /unexpected error occurred/i.test(e.message)) { /* log raw cause, alert ops */ }\n  throw e;\n}","preventionTips":["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."],"tags":["selected-calendars","internal-error","non-error-throw","nestjs","unhandled"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}