Skip to content

Commit c0c80f7

Browse files
committed
fix: catch URI Malformed error
1 parent 0ef7513 commit c0c80f7

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/shared/remoteSourceTrackingService.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { EOL } from 'node:os';
1111
import { retryDecorator, NotRetryableError } from 'ts-retry-promise';
1212
import { Logger, Org, Messages, Lifecycle, SfError, Connection, lockInit } from '@salesforce/core';
1313
import { env, Duration, parseJsonMap } from '@salesforce/kit';
14+
import { isString } from '@salesforce/ts-types';
1415
import {
1516
ChangeResult,
1617
RemoteChangeElement,
@@ -542,13 +543,19 @@ function getDecodedKeyIfSourceMembersHas({
542543
key: string;
543544
logger: Logger;
544545
}): string {
545-
const originalKeyDecoded = decodeURIComponent(key);
546-
const match = Array.from(sourceMembers.keys()).find(
547-
(memberKey) => decodeURIComponent(memberKey) === originalKeyDecoded
548-
);
549-
if (match) {
550-
logger.debug(`${match} matches already tracked member: ${key}`);
551-
return match;
546+
try {
547+
const originalKeyDecoded = decodeURIComponent(key);
548+
const match = Array.from(sourceMembers.keys()).find(
549+
(memberKey) => decodeURIComponent(memberKey) === originalKeyDecoded
550+
);
551+
if (match) {
552+
logger.debug(`${match} matches already tracked member: ${key}`);
553+
return match;
554+
}
555+
} catch (e: unknown) {
556+
// Log the error and the key
557+
const errMsg = e instanceof Error ? e.message : isString(e) ? e : 'unknown';
558+
logger.debug(`Could not decode metadata key: ${key} due to: ${errMsg}`);
552559
}
553560
return key;
554561
}

test/unit/remoteSourceTracking.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,15 @@ describe('remoteSourceTrackingService', () => {
331331
);
332332
});
333333

334+
it('should not throw for non-decodeable key missing from SourceMember map on get', () => {
335+
// trying to decode '%E0%A4%A' throws a URIError so getDecodedKeyIfSourceMembersHas()
336+
// should not throw when a non-decodeable key is encountered.
337+
const sourceMemberKey = 'Layout__Broker__c-%E0%A4%A';
338+
339+
// @ts-ignore getSourceMember is private
340+
expect(remoteSourceTrackingService.getSourceMember(sourceMemberKey)).to.equal(undefined);
341+
});
342+
334343
it('will match/update encoded SourceMember keys on set', () => {
335344
const maxJson = {
336345
serverMaxRevisionCounter: 2,

0 commit comments

Comments
 (0)