Skip to content

Commit

Permalink
fix(cli): handle non-existent files during codemod execution (#1284)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev authored Aug 27, 2024
1 parent 29cbaa3 commit c78ebc5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/rare-pianos-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@codemod-com/runner": patch
"codemod": patch
---

handles execution error when file path could not be read from
25 changes: 19 additions & 6 deletions packages/runner/src/worker-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,24 @@ export class WorkerManager {
return;
}

const data = (await fs.promises.readFile(filePath, {
encoding: "utf8",
})) as string;
const data = await fs.promises.readFile(filePath, "utf8").catch(() => null);
if (data === null) {
this.__idleWorkerIds.push(id);
this._options.onError?.({
message: "Could not read from file",
filePath: filePath,
});
this._options.onPrinterMessage({
kind: "progress",
processedFileNumber: ++this.__processedFileNumber,
totalFileNumber: this.__totalFileCount,
processedFileName: relative(
this._options.flowSettings.target,
resolve(filePath),
),
});
return;
}

this.__workers[id]?.postMessage({
kind: "runCodemod",
Expand All @@ -136,9 +151,7 @@ export class WorkerManager {
worker.postMessage({ kind: "exit" } satisfies MainThreadMessage);
}

this._options.onPrinterMessage({
kind: "finish",
});
this._options.onPrinterMessage({ kind: "finish" });
}

private _getShouldFinish() {
Expand Down

0 comments on commit c78ebc5

Please sign in to comment.