From 984e27e372ff4d9587ad9ad2dadfb047d5ba09b3 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 11 Apr 2016 17:20:40 -0400 Subject: [PATCH] Better error message for _combineFiles lazy/bare mismatch. --- tools/isobuild/import-scanner.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tools/isobuild/import-scanner.js b/tools/isobuild/import-scanner.js index b862d0a536..dc46b667b0 100644 --- a/tools/isobuild/import-scanner.js +++ b/tools/isobuild/import-scanner.js @@ -1,7 +1,8 @@ import assert from "assert"; +import {inspect} from "util"; import {Script} from "vm"; import { - isString, isEmpty, has, keys, each, map, without + isString, isEmpty, has, keys, each, map, omit, } from "underscore"; import {sha1, readAndWatchFileWithHash} from "../fs/watch.js"; import {matches as archMatches} from "../utils/archinfo.js"; @@ -184,10 +185,28 @@ export default class ImportScanner { // maps and updating all other properties appropriately. Once this // combination is done, oldFile should be kept and newFile discarded. _combineFiles(oldFile, newFile) { + function checkProperty(name) { + if (has(oldFile, name)) { + if (! has(newFile, name)) { + newFile[name] = oldFile[name]; + } + } else if (has(newFile, name)) { + oldFile[name] = newFile[name]; + } + + if (oldFile[name] !== newFile[name]) { + throw new Error( + "Attempting to combine different files:\n" + + inspect(omit(oldFile, "dataString")) + "\n" + + inspect(omit(newFile, "dataString")) + "\n" + ); + } + } + // Since we're concatenating the files together, they must be either // both lazy or both eager. Same for bareness. - assert.strictEqual(oldFile.lazy, newFile.lazy); - assert.strictEqual(oldFile.bare, newFile.bare); + checkProperty("lazy"); + checkProperty("bare"); function getChunk(file) { const consumer = file.sourceMap &&