Skip to content

fix: tests failing in getOutlookEvents.spec.ts#3239

Open
SantamRC wants to merge 4 commits intoRocketChat:masterfrom
SantamRC:fix-test-failing-outlook
Open

fix: tests failing in getOutlookEvents.spec.ts#3239
SantamRC wants to merge 4 commits intoRocketChat:masterfrom
SantamRC:fix-test-failing-outlook

Conversation

@SantamRC
Copy link
Contributor

@SantamRC SantamRC commented Mar 7, 2026

When running tests in getOutlookEvents.spec.ts, 3 tests were failing.
Logs,

● Exchange URL Sanitization › Fallback for malformed URLs › handles URLs without protocol mail.example.com:443/ews into https://mail.example.com:443/ews/exchange.asmx

    expect(received).toBe(expected) // Object.is equality

    Expected: "https://mail.example.com:443/ews/exchange.asmx"
    Received: "https://mail.example.com/ews/exchange.asmx"

      125 |     ])('handles URLs without protocol %s into %s', (input, expected) => {
      126 |       const result = sanitizeExchangeUrl(input);
    > 127 |       expect(result).toBe(expected);
          |                      ^
      128 |     });
      129 |   });


● Exchange URL Sanitization › URL validation and error handling › Invalid URL structures › throws error for invalid URL invalid://domain.com with message containing Invalid protocol "invalid:". Only HTTP and HTTPS are supported

    expect(received).toThrow(expected)

    Expected pattern: /Invalid protocol "invalid:". Only HTTP and HTTPS are supported/

    Received function did not throw

      190 |         'throws error for invalid URL %s with message containing %s',
      191 |         (input, expectedErrorPart) => {
    > 192 |           expect(() => sanitizeExchangeUrl(input)).toThrow(
          |                                                    ^
      193 |             new RegExp(expectedErrorPart)
      194 |           );
      195 |         }


● Exchange URL Sanitization › URL validation and error handling › Invalid URL structures › throws error for invalid URL https:// with message containing URL must have a valid hostname

    expect(received).toThrow(expected)

    Expected pattern: /URL must have a valid hostname/
    Received message: "Failed to create valid Exchange URL from \"https://\".·
            Original error: TypeError: Invalid URL.·
            Fallback error: TypeError: Invalid URL.·
            Please ensure the URL includes a valid protocol (http:// or https://) and hostname."

          229 |       });
          230 |
        > 231 |       throw new Error(errorMessage);
              |             ^
          232 |     }
          233 |   }
          234 | };

Changes:

  • Added protocol validation in fallback path to catch invalid protocols
  • Added port preservation logic for explicit default ports (443/https, 80/http)
  • Improved error handling to re-throw validation errors from fallback
  • Added special case detection for URLs without protocols that include ports (e.g., domain.com:443)

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of Outlook calendar integration by preserving explicit default ports during URL handling.
    • Clearer, more informative error messages for protocol and hostname issues, including explicit handling of empty hostnames and invalid protocol cases.
    • Enhanced diagnostics: original and fallback error details are consolidated for clearer reporting while retaining original error information in logs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

Walkthrough

Adds a helper buildFinalUrl to preserve explicit default ports when serializing URLs, replaces direct url.toString() uses with that helper, strengthens fallback URL parsing with protocol and hostname validation, refactors error handling to report original and fallback errors separately, and improves logging and inline comments.

Changes

Cohort / File(s) Summary
URL sanitization & error handling
src/outlookCalendar/getOutlookEvents.ts
Adds buildFinalUrl(url, originalUrl) to preserve explicit default ports and replace url.toString() usage; strengthens fallback parsing with protocol and hostname validation and an explicit empty-hostname error; consolidates original and fallback errors into a composite message; improves logging and inline documentation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing three failing tests in getOutlookEvents.spec.ts related to URL sanitization and validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/outlookCalendar/getOutlookEvents.ts (1)

175-194: ⚠️ Potential issue | 🟡 Minor

Normalize the raw URL once before branching on these edge cases.

Line 179 checks the untrimmed serverUrl, while Line 190 trims before fallback construction. That means inputs like ' mail.example.com:443/ews ' now rethrow Invalid protocol instead of taking the fallback that would succeed after trimming. The empty-hostname remap also only recognizes https://, so bare http:// still falls through to the composite error even though HTTP is supported.

Suggested fix
+    const trimmedServerUrl = serverUrl.trim();
     const errorMessage = error instanceof Error ? error.message : String(error);

     // Re-throw validation errors without attempting fallback, except for cases
     // where the URL looks like it's missing a protocol (e.g., "domain.com:443")
-    if (errorMessage.includes('Invalid protocol') && !serverUrl.match(/^[a-z0-9.-]+:\d+/i)) {
+    if (
+      errorMessage.includes('Invalid protocol') &&
+      !trimmedServerUrl.match(/^[a-z0-9.-]+:\d+/i)
+    ) {
       throw error;
     }

     // Try to fix common URL issues
-    let fallbackUrl = serverUrl.trim();
+    let fallbackUrl = trimmedServerUrl;-      if (fallbackErrorMsg.includes('Invalid URL') && fallbackUrl === 'https://') {
+      if (
+        fallbackErrorMsg.includes('Invalid URL') &&
+        /^https?:\/\/$/.test(fallbackUrl)
+      ) {
         throw new Error('URL must have a valid hostname');
       }

Also applies to: 249-252

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/outlookCalendar/getOutlookEvents.ts` around lines 175 - 194, Trim and
normalize serverUrl once at the top of the URL-error handling branch (e.g.,
replace usages of serverUrl with a new normalizedServerUrl = serverUrl.trim())
and use normalizedServerUrl for the Invalid protocol check (the regex
/^[a-z0-9.-]+:\d+/i) and all subsequent fallback logic; ensure the "add
protocol" check and empty-hostname remap use the normalized value and accept
both http and https (use /^https?:\/\// when detecting existing protocol and
allow remapping for http as well). Apply the same normalization change to the
later fallback block referenced around the empty-hostname remap so both blocks
use the same normalizedServerUrl and consistent protocol handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/outlookCalendar/getOutlookEvents.ts`:
- Around line 219-228: The code inconsistently preserves default ports: the main
branch uses url.toString() (which drops default ports) while the fallback uses
serverUrl.match(/:(\d+)/) to reconstruct a port, which can mis-detect ports
outside the authority; update the fallback to read the port from the parsed URL
object (use url.port or url.hostname/url.host) instead of regexing serverUrl,
and apply the same port-preservation logic used in the fallback to the primary
path (or decide to always omit default ports). Concretely, change the port
extraction to use url.port and only append `${url.hostname}:${port}` when
url.port is present and not a non-default port, and ensure the same finalUrl
construction is used in both branches (variables: url, serverUrl, finalUrl).

---

Outside diff comments:
In `@src/outlookCalendar/getOutlookEvents.ts`:
- Around line 175-194: Trim and normalize serverUrl once at the top of the
URL-error handling branch (e.g., replace usages of serverUrl with a new
normalizedServerUrl = serverUrl.trim()) and use normalizedServerUrl for the
Invalid protocol check (the regex /^[a-z0-9.-]+:\d+/i) and all subsequent
fallback logic; ensure the "add protocol" check and empty-hostname remap use the
normalized value and accept both http and https (use /^https?:\/\// when
detecting existing protocol and allow remapping for http as well). Apply the
same normalization change to the later fallback block referenced around the
empty-hostname remap so both blocks use the same normalizedServerUrl and
consistent protocol handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 065d27b7-04bf-46a5-8169-ca843e1daa86

📥 Commits

Reviewing files that changed from the base of the PR and between 49261f5 and 4ed5ac9.

📒 Files selected for processing (1)
  • src/outlookCalendar/getOutlookEvents.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript strict mode enabled in TypeScript configuration
Use React functional components with hooks instead of class components
Follow FSA (Flux Standard Action) pattern for Redux actions
Use camelCase for file names and PascalCase for component file names
All code must pass ESLint and TypeScript checks
Write self-documenting code with clear naming; avoid unnecessary comments except for complex business logic or non-obvious decisions
Use Fuselage components from @rocket.chat/fuselage for all UI work and only create custom components when Fuselage doesn't provide what's needed
Check Theme.d.ts for valid color tokens when using Fuselage components
Use defensive coding with optional chaining and fallbacks for Linux-only APIs (process.getuid(), process.getgid(), process.geteuid(), process.getegid()) to ensure cross-platform compatibility across Windows, macOS, and Linux

Files:

  • src/outlookCalendar/getOutlookEvents.ts
src/outlookCalendar/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/outlookCalendar/AGENTS.md)

src/outlookCalendar/**/*.{ts,tsx}: Use createClassifiedError() from errorClassification.ts for user-facing errors to provide error categorization, user-friendly messages, and structured error context
Always use outlookError() for errors as it logs regardless of verbose mode settings, ensuring errors are always visible to users

Files:

  • src/outlookCalendar/getOutlookEvents.ts
🧠 Learnings (3)
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*.{ts,tsx} : Always use outlookError() for errors as it logs regardless of verbose mode settings, ensuring errors are always visible to users

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*.{ts,tsx} : Use `createClassifiedError()` from `errorClassification.ts` for user-facing errors to provide error categorization, user-friendly messages, and structured error context

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*(!preload).ts?(x) : Always use the centralized logger from `logger.ts` (outlookLog, outlookDebug, outlookError, outlookWarn, outlookEventDetail) instead of console.log() for Outlook Calendar module logging

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
🪛 ESLint
src/outlookCalendar/getOutlookEvents.ts

[error] 179-179: Replace errorMessage.includes('Invalid·protocol')·&&·!serverUrl.match(/^[a-z0-9.-]+:\d+/i) with ⏎······errorMessage.includes('Invalid·protocol')·&&⏎······!serverUrl.match(/^[a-z0-9.-]+:\d+/i)⏎····

(prettier/prettier)


[error] 224-224: Insert ⏎··········

(prettier/prettier)


[error] 225-225: Replace ··(url.protocol·===·'http:'·&&·port·===·'80') with (url.protocol·===·'http:'·&&·port·===·'80')⏎········

(prettier/prettier)


[error] 241-241: Replace ·fallbackError·instanceof·Error·?·fallbackError.message with ⏎········fallbackError·instanceof·Error⏎··········?·fallbackError.message⏎·········

(prettier/prettier)


[error] 244-244: Insert ⏎········

(prettier/prettier)


[error] 245-245: Replace ··fallbackErrorMsg.includes('Invalid·protocol') with fallbackErrorMsg.includes('Invalid·protocol')⏎······

(prettier/prettier)


[error] 250-250: Replace fallbackErrorMsg.includes('Invalid·URL')·&&·fallbackUrl·===·'https://' with ⏎········fallbackErrorMsg.includes('Invalid·URL')·&&⏎········fallbackUrl·===·'https://'⏎······

(prettier/prettier)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/outlookCalendar/getOutlookEvents.ts`:
- Around line 267-269: The branch that treats empty-host errors only for
'https://' must also cover 'http://'; update the conditional that checks
fallbackErrorMsg and fallbackUrl (used in getOutlookEvents flow) to treat both
protocols the same (e.g., change the check from fallbackUrl === 'https://' to
include fallbackUrl === 'http://' or normalize by stripping protocol and
checking for an empty hostname) and throw the same Error('URL must have a valid
hostname') so http and https empty-host cases are handled consistently.
- Around line 204-208: The current heuristic in getOutlookEvents that checks
serverUrl.match(/^[a-z0-9.-]+:\d+/i) treats scheme:port (e.g., "ftp:21") as
host:port; change it to only match real hostnames or IPv4 addresses with ports
(for example require a dot in the hostname or match IPv4), e.g. replace the
regex with one that matches either an IPv4 address or a hostname containing a
dot before the colon (e.g.,
/^(?:\d{1,3}(?:\.\d{1,3}){3}|[a-z0-9-]+\.[a-z0-9.-]+):\d+/i) so that legitimate
schemes like "ftp:21" will not bypass the Invalid protocol re-throw in the error
handling around the Invalid protocol check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7225a0b-2723-4a5f-93ef-ea11268a3e74

📥 Commits

Reviewing files that changed from the base of the PR and between 4ed5ac9 and f94936a.

📒 Files selected for processing (1)
  • src/outlookCalendar/getOutlookEvents.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript strict mode enabled in TypeScript configuration
Use React functional components with hooks instead of class components
Follow FSA (Flux Standard Action) pattern for Redux actions
Use camelCase for file names and PascalCase for component file names
All code must pass ESLint and TypeScript checks
Write self-documenting code with clear naming; avoid unnecessary comments except for complex business logic or non-obvious decisions
Use Fuselage components from @rocket.chat/fuselage for all UI work and only create custom components when Fuselage doesn't provide what's needed
Check Theme.d.ts for valid color tokens when using Fuselage components
Use defensive coding with optional chaining and fallbacks for Linux-only APIs (process.getuid(), process.getgid(), process.geteuid(), process.getegid()) to ensure cross-platform compatibility across Windows, macOS, and Linux

Files:

  • src/outlookCalendar/getOutlookEvents.ts
src/outlookCalendar/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/outlookCalendar/AGENTS.md)

src/outlookCalendar/**/*.{ts,tsx}: Use createClassifiedError() from errorClassification.ts for user-facing errors to provide error categorization, user-friendly messages, and structured error context
Always use outlookError() for errors as it logs regardless of verbose mode settings, ensuring errors are always visible to users

Files:

  • src/outlookCalendar/getOutlookEvents.ts
🧠 Learnings (3)
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*.{ts,tsx} : Use `createClassifiedError()` from `errorClassification.ts` for user-facing errors to provide error categorization, user-friendly messages, and structured error context

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*.{ts,tsx} : Always use outlookError() for errors as it logs regardless of verbose mode settings, ensuring errors are always visible to users

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*(!preload).ts?(x) : Always use the centralized logger from `logger.ts` (outlookLog, outlookDebug, outlookError, outlookWarn, outlookEventDetail) instead of console.log() for Outlook Calendar module logging

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
🪛 ESLint
src/outlookCalendar/getOutlookEvents.ts

[error] 122-122: Insert ⏎······

(prettier/prettier)


[error] 123-123: Replace ··(url.protocol·===·'http:'·&&·explicitPort·===·'80') with (url.protocol·===·'http:'·&&·explicitPort·===·'80')⏎····

(prettier/prettier)


[error] 206-206: Replace errorMessage.includes('Invalid·protocol')·&&·!serverUrl.match(/^[a-z0-9.-]+:\d+/i) with ⏎······errorMessage.includes('Invalid·protocol')·&&⏎······!serverUrl.match(/^[a-z0-9.-]+:\d+/i)⏎····

(prettier/prettier)


[error] 259-259: Replace ·fallbackError·instanceof·Error·?·fallbackError.message with ⏎········fallbackError·instanceof·Error⏎··········?·fallbackError.message⏎·········

(prettier/prettier)


[error] 262-262: Insert ⏎········

(prettier/prettier)


[error] 263-263: Replace ··fallbackErrorMsg.includes('Invalid·protocol') with fallbackErrorMsg.includes('Invalid·protocol')⏎······

(prettier/prettier)


[error] 268-268: Replace fallbackErrorMsg.includes('Invalid·URL')·&&·fallbackUrl·===·'https://' with ⏎········fallbackErrorMsg.includes('Invalid·URL')·&&⏎········fallbackUrl·===·'https://'⏎······

(prettier/prettier)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/outlookCalendar/getOutlookEvents.ts`:
- Around line 122-123: The multiline boolean condition in getOutlookEvents using
(url.protocol === 'https:' && explicitPort === '443') || (url.protocol ===
'http:' && explicitPort === '80') is triggering Prettier/ESLint failures;
reformat it to satisfy Prettier (e.g., collapse to a single line or follow the
project’s preferred wrapping) and apply the same formatting fixes to the other
offending condition blocks in this file (the other occurrences that check
url.protocol and explicitPort). Locate the checks in getOutlookEvents where url
and explicitPort are compared and adjust their formatting to match the project's
Prettier rules so the file passes linting.
- Around line 204-209: The current check in getOutlookEvents.ts rethrows
"Invalid protocol" unless serverUrl matches only IPv4 or dotted hostnames;
update the regex used in the if (errorMessage.includes('Invalid protocol') &&
!serverUrl.match(...)) to also accept single-label hostnames (e.g., "mail" or
"localhost") with ports by changing the hostname part from
[a-z0-9-]+\.[a-z0-9.-]+ to allow an optional dot — e.g.
[a-z0-9-]+(?:\.[a-z0-9.-]+)? — so serverUrl like "mail:443/ews" or
"localhost:443/ews" will not be rethrown and can reach the fallback
normalization branch.
- Around line 118-124: The current port-extraction regex (used in portMatch =
originalUrl.match(...)) only catches non-bracketed hosts so URLs like
https://[2001:db8::1]:443/... lose the explicit port; update the regex to also
match bracketed IPv6 hosts (e.g. something like
/(?:\/\/|^)(?:\[[^\]]+\]|[^/:]+):(\d+)/) so explicitPort captures ports after
[ipv6] as well, keep the existing logic that checks url.protocol and
explicitPort and return baseUrl.replace(url.host,
`${url.hostname}:${explicitPort}`) when restoring default ports.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6ea24792-f948-4b26-99fa-827ae0dd7c5c

📥 Commits

Reviewing files that changed from the base of the PR and between f94936a and f4bccb6.

📒 Files selected for processing (1)
  • src/outlookCalendar/getOutlookEvents.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript strict mode enabled in TypeScript configuration
Use React functional components with hooks instead of class components
Follow FSA (Flux Standard Action) pattern for Redux actions
Use camelCase for file names and PascalCase for component file names
All code must pass ESLint and TypeScript checks
Write self-documenting code with clear naming; avoid unnecessary comments except for complex business logic or non-obvious decisions
Use Fuselage components from @rocket.chat/fuselage for all UI work and only create custom components when Fuselage doesn't provide what's needed
Check Theme.d.ts for valid color tokens when using Fuselage components
Use defensive coding with optional chaining and fallbacks for Linux-only APIs (process.getuid(), process.getgid(), process.geteuid(), process.getegid()) to ensure cross-platform compatibility across Windows, macOS, and Linux

Files:

  • src/outlookCalendar/getOutlookEvents.ts
src/outlookCalendar/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/outlookCalendar/AGENTS.md)

src/outlookCalendar/**/*.{ts,tsx}: Use createClassifiedError() from errorClassification.ts for user-facing errors to provide error categorization, user-friendly messages, and structured error context
Always use outlookError() for errors as it logs regardless of verbose mode settings, ensuring errors are always visible to users

Files:

  • src/outlookCalendar/getOutlookEvents.ts
🧠 Learnings (3)
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*.{ts,tsx} : Always use outlookError() for errors as it logs regardless of verbose mode settings, ensuring errors are always visible to users

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*.{ts,tsx} : Use `createClassifiedError()` from `errorClassification.ts` for user-facing errors to provide error categorization, user-friendly messages, and structured error context

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*(!preload).ts?(x) : Always use the centralized logger from `logger.ts` (outlookLog, outlookDebug, outlookError, outlookWarn, outlookEventDetail) instead of console.log() for Outlook Calendar module logging

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
🪛 ESLint
src/outlookCalendar/getOutlookEvents.ts

[error] 122-122: Insert ⏎······

(prettier/prettier)


[error] 123-123: Replace ··(url.protocol·===·'http:'·&&·explicitPort·===·'80') with (url.protocol·===·'http:'·&&·explicitPort·===·'80')⏎····

(prettier/prettier)


[error] 207-207: Replace errorMessage.includes('Invalid·protocol')·&&·!serverUrl.match(/^(?:\d{1,3}(?:\.\d{1,3}){3}|[a-z0-9-]+\.[a-z0-9.-]+):\d+/i) with ⏎······errorMessage.includes('Invalid·protocol')·&&⏎······!serverUrl.match(⏎········/^(?:\d{1,3}(?:\.\d{1,3}){3}|[a-z0-9-]+\.[a-z0-9.-]+):\d+/i⏎······)⏎····

(prettier/prettier)


[error] 260-260: Replace ·fallbackError·instanceof·Error·?·fallbackError.message with ⏎········fallbackError·instanceof·Error⏎··········?·fallbackError.message⏎·········

(prettier/prettier)


[error] 263-263: Insert ⏎········

(prettier/prettier)


[error] 264-264: Replace ··fallbackErrorMsg.includes('Invalid·protocol') with fallbackErrorMsg.includes('Invalid·protocol')⏎······

(prettier/prettier)


[error] 269-269: Replace fallbackErrorMsg.includes('Invalid·URL')·&&·fallbackUrl.match(/^https?:\/\/$/) with ⏎········fallbackErrorMsg.includes('Invalid·URL')·&&⏎········fallbackUrl.match(/^https?:\/\/$/)⏎······

(prettier/prettier)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/outlookCalendar/getOutlookEvents.ts (1)

289-292: Inconsistent indentation in error message template.

The multiline template literal includes leading spaces from the source code indentation, which will appear in the error message output. This results in "Original error:" and subsequent lines being indented with extra spaces.

♻️ Suggested fix
-      const fallbackErrorMessage = `Failed to create valid Exchange URL from "${serverUrl}".
-        Original error: ${errorMessage}.
-        Fallback error: ${fallbackErrorMsg}.
+      const fallbackErrorMessage = `Failed to create valid Exchange URL from "${serverUrl}". ` +
+        `Original error: ${errorMessage}. ` +
+        `Fallback error: ${fallbackErrorMsg}. ` +
         Please ensure the URL includes a valid protocol (http:// or https://) and hostname.`;

Or use a single line if preferred for error messages.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/outlookCalendar/getOutlookEvents.ts` around lines 289 - 292, The
multiline template assigned to fallbackErrorMessage in getOutlookEvents.ts
contains source-code indentation that will be preserved in the error string;
remove the leading spaces by collapsing it into a single-line message or by
trimming the template (e.g., build the string without leading spaces or call
.trim() on the template) and ensure it still includes serverUrl, errorMessage,
and fallbackErrorMsg for context.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/outlookCalendar/getOutlookEvents.ts`:
- Around line 289-292: The multiline template assigned to fallbackErrorMessage
in getOutlookEvents.ts contains source-code indentation that will be preserved
in the error string; remove the leading spaces by collapsing it into a
single-line message or by trimming the template (e.g., build the string without
leading spaces or call .trim() on the template) and ensure it still includes
serverUrl, errorMessage, and fallbackErrorMsg for context.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 928aacab-dbca-41f3-838b-699a885309ff

📥 Commits

Reviewing files that changed from the base of the PR and between f4bccb6 and 812acef.

📒 Files selected for processing (1)
  • src/outlookCalendar/getOutlookEvents.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript strict mode enabled in TypeScript configuration
Use React functional components with hooks instead of class components
Follow FSA (Flux Standard Action) pattern for Redux actions
Use camelCase for file names and PascalCase for component file names
All code must pass ESLint and TypeScript checks
Write self-documenting code with clear naming; avoid unnecessary comments except for complex business logic or non-obvious decisions
Use Fuselage components from @rocket.chat/fuselage for all UI work and only create custom components when Fuselage doesn't provide what's needed
Check Theme.d.ts for valid color tokens when using Fuselage components
Use defensive coding with optional chaining and fallbacks for Linux-only APIs (process.getuid(), process.getgid(), process.geteuid(), process.getegid()) to ensure cross-platform compatibility across Windows, macOS, and Linux

Files:

  • src/outlookCalendar/getOutlookEvents.ts
src/outlookCalendar/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/outlookCalendar/AGENTS.md)

src/outlookCalendar/**/*.{ts,tsx}: Use createClassifiedError() from errorClassification.ts for user-facing errors to provide error categorization, user-friendly messages, and structured error context
Always use outlookError() for errors as it logs regardless of verbose mode settings, ensuring errors are always visible to users

Files:

  • src/outlookCalendar/getOutlookEvents.ts
🧠 Learnings (3)
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*.{ts,tsx} : Use `createClassifiedError()` from `errorClassification.ts` for user-facing errors to provide error categorization, user-friendly messages, and structured error context

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*.{ts,tsx} : Always use outlookError() for errors as it logs regardless of verbose mode settings, ensuring errors are always visible to users

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
📚 Learning: 2026-03-06T19:31:11.422Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.Electron PR: 0
File: src/outlookCalendar/AGENTS.md:0-0
Timestamp: 2026-03-06T19:31:11.422Z
Learning: Applies to src/outlookCalendar/**/*(!preload).ts?(x) : Always use the centralized logger from `logger.ts` (outlookLog, outlookDebug, outlookError, outlookWarn, outlookEventDetail) instead of console.log() for Outlook Calendar module logging

Applied to files:

  • src/outlookCalendar/getOutlookEvents.ts
🔇 Additional comments (6)
src/outlookCalendar/getOutlookEvents.ts (6)

104-132: Well-designed helper for preserving explicit default ports.

The buildFinalUrl helper correctly addresses the URL serialization asymmetry. The regex on line 119 properly handles:

  • Regular hostnames (mail.example.com:443)
  • IPv6 addresses in brackets ([2001:db8::1]:443)
  • URLs without protocol (domain.com:443)

The logic cleanly separates the check for non-default ports (already preserved by toString()) from explicit default ports that need restoration.


189-189: LGTM!

Consistent use of buildFinalUrl in the main path aligns with the fallback path behavior.


205-217: LGTM!

The updated regex pattern correctly allows single-label hostnames (e.g., localhost:443, mail:443) to proceed to the fallback path rather than being incorrectly rejected as invalid protocols.


245-250: LGTM!

Protocol validation in the fallback path mirrors the main path, ensuring consistent behavior regardless of which code path handles the URL.


255-255: LGTM!

Correctly passes the original serverUrl to buildFinalUrl to preserve port information from the user's input.


282-287: LGTM!

The regex /^https?:\/\/$/ correctly handles both http:// and https:// empty hostname cases, addressing the prior inconsistency between protocols.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant