Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch URI Malformed error #531

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/shared/remoteSourceTrackingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EOL } from 'node:os';
import { retryDecorator, NotRetryableError } from 'ts-retry-promise';
import { Logger, Org, Messages, Lifecycle, SfError, Connection, lockInit } from '@salesforce/core';
import { env, Duration, parseJsonMap } from '@salesforce/kit';
import { isString } from '@salesforce/ts-types';
import {
ChangeResult,
RemoteChangeElement,
Expand Down Expand Up @@ -542,13 +543,19 @@ function getDecodedKeyIfSourceMembersHas({
key: string;
logger: Logger;
}): string {
const originalKeyDecoded = decodeURIComponent(key);
const match = Array.from(sourceMembers.keys()).find(
(memberKey) => decodeURIComponent(memberKey) === originalKeyDecoded
);
if (match) {
logger.debug(`${match} matches already tracked member: ${key}`);
return match;
try {
const originalKeyDecoded = decodeURIComponent(key);
const match = Array.from(sourceMembers.keys()).find(
(memberKey) => decodeURIComponent(memberKey) === originalKeyDecoded
);
if (match) {
logger.debug(`${match} matches already tracked member: ${key}`);
return match;
}
} catch (e: unknown) {
// Log the error and the key
const errMsg = e instanceof Error ? e.message : isString(e) ? e : 'unknown';
logger.debug(`Could not decode metadata key: ${key} due to: ${errMsg}`);
}
return key;
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit/remoteSourceTracking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ describe('remoteSourceTrackingService', () => {
);
});

it('should not throw for non-decodeable key missing from SourceMember map on get', () => {
// trying to decode '%E0%A4%A' throws a URIError so getDecodedKeyIfSourceMembersHas()
// should not throw when a non-decodeable key is encountered.
const sourceMemberKey = 'Layout__Broker__c-%E0%A4%A';

// @ts-ignore getSourceMember is private
expect(remoteSourceTrackingService.getSourceMember(sourceMemberKey)).to.equal(undefined);
});

it('will match/update encoded SourceMember keys on set', () => {
const maxJson = {
serverMaxRevisionCounter: 2,
Expand Down