Print a shorter error in tsc_wrapped FileCache
When the TypeScript compiler tries to read a file from the cache, but the file wasn't declared as an input, this indicates a bug in the compiler.
However the result is a massive data dump to the terminal, observed in e.g. https://circleci.com/gh/angular/angular/382012
To make the output less huge, only print the first 100 keys in the cache.
Note that this might make it harder to debug a failure by reasoning about all the entries that *are* present in the cache, though.
PiperOrigin-RevId: 257096480
diff --git a/internal/tsc_wrapped/cache.ts b/internal/tsc_wrapped/cache.ts
index 486bf4e..7fa5f3e 100644
--- a/internal/tsc_wrapped/cache.ts
+++ b/internal/tsc_wrapped/cache.ts
@@ -204,9 +204,15 @@
getLastDigest(filePath: string): string {
const digest = this.lastDigests.get(filePath);
if (!digest) {
- throw new Error(
- `missing input digest for ${filePath}.` +
- `(only have ${Array.from(this.lastDigests.keys())})`);
+ const errorMsg = `missing input digest for ${filePath}. `;
+ let entriesToPrint = Array.from(this.lastDigests.keys());
+ if (entriesToPrint.length > 100) {
+ throw new Error(
+ errorMsg +
+ `(only have ${entriesToPrint.slice(0, 100)} and ${
+ entriesToPrint.length - 100} more)`);
+ }
+ throw new Error(errorMsg + `(only have ${entriesToPrint})`);
}
return digest;
}