Repository navigation
fix(campaign_manager): handling normalizePhone function error - #4592
Conversation
Summary by CodeRabbit
WalkthroughnormalizePhone now wraps phone parsing/validation in a try/catch and throws an InstrumentationError containing the original parse error message on failure. A unit test was added to assert the detailed error when countryCode is null. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant util as normalizePhone
participant lib as parsePhoneNumber
Note over Caller,util #E8F0FE: New flow adds try/catch and propagates parse errors
Caller->>util: normalizePhone(input, countryCode)
util->>lib: parsePhoneNumber(input, countryCode)
alt parse succeeds and is valid
lib-->>util: PhoneNumber object
util-->>Caller: return phoneNumber.format('E.164')
else parse fails or invalid
lib-->>util: throws ParseError
util-->>util: catch error
util-->>Caller: throw InstrumentationError("Invalid phone number with error: " + error)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Suggestions:
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/v0/destinations/campaign_manager/util.test.js (2)
58-64: Stabilize the assertion; avoid depending on libphonenumber-js error wordingAsserting the full vendor error text is brittle across versions. Match the invariant part of the message instead.
- expect(() => normalizePhone(invalidPhone, countryCode)).toThrow( - 'Invalid phone number with error: ParseError: INVALID_COUNTRY', - ); + expect(() => normalizePhone(invalidPhone, countryCode)).toThrow(/Invalid phone number/);
1-1: Remove unused import (ESLint: no-unused-vars)
sha256isn’t used in this test file.-const sha256 = require('sha256');src/v0/destinations/campaign_manager/util.js (1)
56-64: Don’t double-wrap errors; return a consistent messageCurrently, throwing
InstrumentationError('Invalid phone number')insidetryis caught and re-wrapped as"Invalid phone number with error: InstrumentationError: Invalid phone number". This is noisy and couples tests to library error strings. Prefer preserving existingInstrumentationErrorand emitting a stable message for other errors.} catch (error) { - throw new InstrumentationError(`Invalid phone number with error: ${error}`); + if (error instanceof InstrumentationError) { + throw error; // already normalized + } + throw new InstrumentationError('Invalid phone number'); }Note: If you adopt this, update the new test to assert a substring (e.g.,
/Invalid phone number/) rather than the full vendor message.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src/v0/destinations/campaign_manager/util.js(2 hunks)src/v0/destinations/campaign_manager/util.test.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit configuration file
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/v0/destinations/campaign_manager/util.test.jssrc/v0/destinations/campaign_manager/util.js
🧬 Code graph analysis (1)
src/v0/destinations/campaign_manager/util.test.js (1)
src/v0/destinations/campaign_manager/util.js (1)
normalizePhone(55-65)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/v0/destinations/campaign_manager/util.js (1)
100-100: All normalizeAndHash call sites verified
I’ve inspected everynormalizeAndHash(invocation across the repo. Only thehashedPhoneNumbercall insrc/v0/destinations/campaign_manager/util.js(lines 98–101) passes an options object—and it correctly includes{ countryCode: payload.addressInfo?.countryCode }. No other calls supply an options shape, so this change is isolated and ready to merge.
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
4b4fb2e to
5a3b888
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/v0/destinations/campaign_manager/util.test.js (2)
58-64: Make the assertion resilient and fix test name grammarAvoid coupling to libphonenumber-js’s exact error string; assert a stable pattern instead and tighten the test title wording.
- it('should throw an InstrumentationError when the phone number is with invalid country code', () => { + it('should throw an InstrumentationError when the country code is invalid', () => { const invalidPhone = '1234567890'; const countryCode = null; - expect(() => normalizePhone(invalidPhone, countryCode)).toThrow( - 'Invalid phone number with error: ParseError: INVALID_COUNTRY', - ); + expect(() => normalizePhone(invalidPhone, countryCode)).toThrow( + /Invalid phone number with error: .*INVALID_COUNTRY/, + ); });
58-64: Broaden coverage with a small table-driven testConsider covering a few invalid-country scenarios (null, undefined, empty string, and an invalid ISO code) to prevent regressions.
it.each([ ['null country', null], ['undefined country', undefined], ['empty country', ''], ['invalid ISO', 'ZZ'], ])('should throw for %s', (_label, cc) => { expect(() => normalizePhone('1234567890', cc)).toThrow(/Invalid phone number/); });
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
test/integrations/destinations/campaign_manager/processor/data.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/v0/destinations/campaign_manager/util.js(1 hunks)src/v0/destinations/campaign_manager/util.test.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/v0/destinations/campaign_manager/util.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit configuration file
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/v0/destinations/campaign_manager/util.test.js
🧬 Code graph analysis (1)
src/v0/destinations/campaign_manager/util.test.js (1)
src/v0/destinations/campaign_manager/util.js (1)
normalizePhone(55-65)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/v0/destinations/campaign_manager/util.test.js (1)
58-64: Investigate error class and function definitions
Running searches forInstrumentationErroryielded no references in the repo, andnormalizePhoneappears insrc/v0/destinations/campaign_manager/util.js. Since the error class isn’t locally defined or exported, you can’t import it in tests. Keep the existing message assertion only.
|
Allure Test reports for this run are available at:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4592 +/- ##
========================================
Coverage 91.79% 91.79%
========================================
Files 642 642
Lines 33928 33930 +2
Branches 8040 8040
========================================
+ Hits 31143 31145 +2
- Misses 2533 2555 +22
+ Partials 252 230 -22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Allure Test reports for this run are available at:
|
|



What are the changes introduced in this PR?
Add proper error handling for invalid phone numbers in Campaign Manager normalizePhone function
Note: This will not solve the actual integration issue. We will handle it seperately.Problem
The
normalizePhonefunction was throwing unhandled 500 error (because ofparsePhoneNumberwas throwing unhandled INVALID_COUNTRY errors fromlibphonenumber-js) for invalid phone numbers instead of throwing proper 400 errors.Solution
Added proper error handling to ensure the function always either returns a valid E.164 formatted phone number or throws an
InstrumentationError.Changes
throw new InstrumentationError('Invalid phone number')for invalid casesundefinedImpact
This ensures the Campaign Manager destination properly validates phone numbers and provides clear error messages when normalization fails, improving overall data integrity.
What is the related Linear task?
Resolves INT-4069
Please explain the objectives of your changes below
Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
N/A
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
N/A
@coderabbitai review
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.