chore(broccoli): improve `overwrite` error in merge-trees
Modified the error message to include the relative duplicate path, to help in diagnosing the cause of the error message. Closes #2521
This commit is contained in:
parent
2d499de2bd
commit
37fceda7e8
|
@ -55,7 +55,9 @@ describe('MergeTrees', () => {
|
||||||
let treeDiffer = MakeTreeDiffers(['tree1', 'tree2', 'tree3']);
|
let treeDiffer = MakeTreeDiffers(['tree1', 'tree2', 'tree3']);
|
||||||
let treeMerger = mergeTrees(['tree1', 'tree2', 'tree3'], 'dest', {});
|
let treeMerger = mergeTrees(['tree1', 'tree2', 'tree3'], 'dest', {});
|
||||||
expect(() => treeMerger.rebuild(treeDiffer.diffTrees()))
|
expect(() => treeMerger.rebuild(treeDiffer.diffTrees()))
|
||||||
.toThrowError("`overwrite` option is required for handling duplicates.");
|
.toThrowError(
|
||||||
|
'Duplicate path found while merging trees. Path: "foo.js".\n' +
|
||||||
|
'Either remove the duplicate or enable the "overwrite" option for this merge.');
|
||||||
|
|
||||||
testDir = {
|
testDir = {
|
||||||
'tree1': {'foo.js': mockfs.file({content: 'tree1/foo.js content', mtime: new Date(1000)})},
|
'tree1': {'foo.js': mockfs.file({content: 'tree1/foo.js content', mtime: new Date(1000)})},
|
||||||
|
@ -82,6 +84,8 @@ describe('MergeTrees', () => {
|
||||||
testDir.tree2['foo.js'] = mockfs.file({content: 'tree2/foo.js content', mtime: new Date(1000)});
|
testDir.tree2['foo.js'] = mockfs.file({content: 'tree2/foo.js content', mtime: new Date(1000)});
|
||||||
mockfs(testDir);
|
mockfs(testDir);
|
||||||
expect(() => treeMerger.rebuild(treeDiffer.diffTrees()))
|
expect(() => treeMerger.rebuild(treeDiffer.diffTrees()))
|
||||||
.toThrowError("`overwrite` option is required for handling duplicates.");
|
.toThrowError(
|
||||||
|
'Duplicate path found while merging trees. Path: "foo.js".\n' +
|
||||||
|
'Either remove the duplicate or enable the "overwrite" option for this merge.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,11 @@ function outputFileSync(sourcePath, destPath) {
|
||||||
symlinkOrCopySync(sourcePath, destPath);
|
symlinkOrCopySync(sourcePath, destPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pathOverwrittenError(path) {
|
||||||
|
const msg = 'Either remove the duplicate or enable the "overwrite" option for this merge.';
|
||||||
|
return new Error(`Duplicate path found while merging trees. Path: "${path}".\n${msg}`);
|
||||||
|
}
|
||||||
|
|
||||||
export class MergeTrees implements DiffingBroccoliPlugin {
|
export class MergeTrees implements DiffingBroccoliPlugin {
|
||||||
private pathCache: {[key: string]: number[]} = Object.create(null);
|
private pathCache: {[key: string]: number[]} = Object.create(null);
|
||||||
public options: MergeTreesOptions;
|
public options: MergeTreesOptions;
|
||||||
|
@ -59,7 +64,7 @@ export class MergeTrees implements DiffingBroccoliPlugin {
|
||||||
// ASSERT(contains(pathsToEmit, changedPath));
|
// ASSERT(contains(pathsToEmit, changedPath));
|
||||||
cache.unshift(index);
|
cache.unshift(index);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("`overwrite` option is required for handling duplicates.");
|
throw pathOverwrittenError(changedPath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -79,7 +84,7 @@ export class MergeTrees implements DiffingBroccoliPlugin {
|
||||||
this.pathCache[removedPath] = undefined;
|
this.pathCache[removedPath] = undefined;
|
||||||
} else if (!emitted[removedPath]) {
|
} else if (!emitted[removedPath]) {
|
||||||
if (cache.length === 1 && !overwrite) {
|
if (cache.length === 1 && !overwrite) {
|
||||||
throw new Error("`overwrite` option is required for handling duplicates.");
|
throw pathOverwrittenError(removedPath);
|
||||||
}
|
}
|
||||||
emit(removedPath);
|
emit(removedPath);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +107,7 @@ export class MergeTrees implements DiffingBroccoliPlugin {
|
||||||
cache.push(index);
|
cache.push(index);
|
||||||
cache.sort((a, b) => a - b);
|
cache.sort((a, b) => a - b);
|
||||||
if (cache.length > 1 && !overwrite) {
|
if (cache.length > 1 && !overwrite) {
|
||||||
throw new Error("`overwrite` option is required for handling duplicates.");
|
throw pathOverwrittenError(changedPath);
|
||||||
}
|
}
|
||||||
if (cache[cache.length - 1] === index && !emitted[changedPath]) {
|
if (cache[cache.length - 1] === index && !emitted[changedPath]) {
|
||||||
emit(changedPath);
|
emit(changedPath);
|
||||||
|
|
Loading…
Reference in New Issue