Skip to content

Commit

Permalink
refactor: meaningful fallback messages for conflicts instead of as
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Mar 29, 2024
1 parent be96906 commit f22fbb9
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/commands/project/delete/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,28 +489,27 @@ const sourceComponentIsNotInMixedDeployDelete =
* @param message
*/
const processConflicts = (conflicts: ChangeResult[], message: string): void => {
if (conflicts.length === 0) {
return;
}

// map do dedupe by name-type-filename
const conflictMap = new Map<string, ConflictResponse>();
conflicts.forEach((c) => {
c.filenames?.forEach((f) => {
conflictMap.set(`${c.name}#${c.type}#${f}`, {
state: 'Conflict',
fullName: c.name as string,
type: c.type as string,
filePath: path.resolve(f),
});
});
});
if (conflicts.length === 0) return;

const reformattedConflicts = Array.from(conflictMap.values());
const reformattedConflicts = Array.from(
// map do dedupe by name-type-filename
new Map(
conflicts.flatMap(changeResultToConflictResponses).map((c) => [`${c.fullName}#${c.type}#${c.filePath}`, c])
).values()
);

writeConflictTable(reformattedConflicts);

const err = new SfError(message, 'sourceConflictDetected');
err.setData(reformattedConflicts);
throw err;
};

/** each ChangeResult can have multiple filenames, each of which becomes a ConflictResponse */
const changeResultToConflictResponses = (cr: ChangeResult): ConflictResponse[] =>
(cr.filenames ?? []).map((f) => ({
state: 'Conflict',
fullName: cr.name ?? '<Name is missing>',
type: cr.type ?? '<Type is missing>',
filePath: path.resolve(f),
}));

0 comments on commit f22fbb9

Please sign in to comment.