diff --git a/change/change-501f9623-19ff-418f-b70c-61580dd1343c.json b/change/change-501f9623-19ff-418f-b70c-61580dd1343c.json new file mode 100644 index 000000000..dfea809e1 --- /dev/null +++ b/change/change-501f9623-19ff-418f-b70c-61580dd1343c.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "type": "patch", + "comment": "Defend against missing files in the hashing logic", + "packageName": "@lage-run/hasher", + "email": "dobes@formative.com", + "dependentChangeType": "patch" + } + ] +} \ No newline at end of file diff --git a/packages/hasher/src/FileHasher.ts b/packages/hasher/src/FileHasher.ts index 5bc7e3f57..3016187a1 100644 --- a/packages/hasher/src/FileHasher.ts +++ b/packages/hasher/src/FileHasher.ts @@ -100,7 +100,7 @@ export class FileHasher { const stats = globStat(files, { cwd: this.options.root }) ?? {}; for (const file of files) { - const stat = stats[file]; + const stat = stats[file] || { mtime: 0n, size: 0 }; const info = this.#store[file]; if (info && stat.mtime === info.mtime && stat.size == info.size) { @@ -113,12 +113,24 @@ export class FileHasher { const updatedHashes = fastHash(updatedFiles, { cwd: this.options.root, concurrency: 4 }) ?? {}; for (const [file, hash] of Object.entries(updatedHashes)) { - const stat = fs.statSync(path.join(this.options.root, file), { bigint: true }); - this.#store[file] = { - mtime: stat.mtimeMs, - size: Number(stat.size), - hash: hash ?? "", - }; + try { + const stat = fs.statSync(path.join(this.options.root, file), { bigint: true }); + this.#store[file] = { + mtime: stat.mtimeMs, + size: Number(stat.size), + hash: hash ?? "", + }; + } catch (e: any) { + if (e.code === "ENOENT") { + this.#store[file] = { + mtime: 0n, + size: 0, + hash: hash ?? "", + }; + } else { + throw e; + } + } hashes[file] = hash ?? ""; }