Skip to content

Commit

Permalink
Merge pull request #4478 from antoine-coulon/avoid-getrepostate-to-crash
Browse files Browse the repository at this point in the history
[rush](package-deps-hash) Avoid defect to be produced when spawned "git hash-object" process stdin fails while computing repo-state
  • Loading branch information
iclanton authored Jan 17, 2024
2 parents fa6fbb1 + 37f6f99 commit b445758
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/package-deps-hash",
"comment": "Handle an edge case in `getRepoState` wherein it tries to asynchronously pipe data to `git hash-object` but the subprocess has already exited.",
"type": "patch"
}
],
"packageName": "@rushstack/package-deps-hash"
}
1 change: 0 additions & 1 deletion libraries/package-deps-hash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
},
"devDependencies": {
"@rushstack/heft": "workspace:*",
"@rushstack/node-core-library": "workspace:*",
"local-node-rig": "workspace:*"
},
"dependencies": {
Expand Down
9 changes: 7 additions & 2 deletions libraries/package-deps-hash/src/getRepoState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type * as child_process from 'child_process';
import { once } from 'events';
import { Readable } from 'stream';
import { Readable, pipeline } from 'stream';

import { Executable, FileSystem, type IExecutableSpawnOptions } from '@rushstack/node-core-library';

Expand Down Expand Up @@ -282,7 +282,12 @@ async function spawnGitAsync(
});

if (stdin) {
stdin.pipe(proc.stdin!);
/**
* For `git hash-object` data is piped in asynchronously. In the event that one of the
* passed filenames cannot be hashed, subsequent writes to `proc.stdin` will error.
* Silence this error since it will be handled by the non-zero exit code of the process.
*/
pipeline(stdin, proc.stdin!, (err) => {});
}

const [status] = await once(proc, 'exit');
Expand Down

0 comments on commit b445758

Please sign in to comment.