Closed jsynacek closed 3 weeks ago
Hello, I have the same issue. From my research, this behaviour appeared in nx@18.2.0.
When I run this command :
$ npx nx affected:build --base="0000000000000000000000000000000000000000" --head="ba25f78f9628a757f1796feb00cd4dd4c2de2c68" --configuration="dev" || echo "Failed"
Output in nx@18.1.0:
$ npx nx affected:build --base="0000000000000000000000000000000000000000" --head="ba25f78f9628a757f1796feb00cd4dd4c2de2c68" --configuration="dev" || echo "Failed"
fatal: bad object 0000000000000000000000000000000000000000
nx affected:build
Run command using --base=[SHA1] (affected by the committed, uncommitted and untracked changes):
--base Base of the current branch (usually main) [string]
or using --base=[SHA1] --head=[SHA2] (affected by the committed changes):
--base Base of the current branch (usually main) [string]
--head Latest commit of the current branch (usually HEAD) [string]
or using:
--files Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces [string]
--uncommitted Uncommitted changes [boolean]
--untracked Untracked changes [boolean]
Options:
--help Show help [boolean]
--version Show version number [boolean]
-c, --configuration This is the configuration to use when performing tasks on projects [string]
--output-style Defines how Nx emits outputs tasks logs [string] [choices: "dynamic", "static", "stream", "stream-without-prefixes"]
--exclude Exclude certain projects from being processed [string]
--parallel Max number of parallel processes [default is 3] [string]
--runner This is the name of the tasks runner configured in nx.json [string]
--graph Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser. [string]
--verbose Prints additional information about the commands (e.g., stack traces) [boolean]
--nxBail Stop command execution after the first failed task [boolean] [default: false]
--nxIgnoreCycles Ignore cycles in the task graph [boolean] [default: false]
--skipNxCache Rerun the tasks even when the results are available in the cache [boolean] [default: false]
Examples:
affected -t custom-target Run custom target for all affected projects
affected -t test --parallel=5 Run tests in parallel
affected -t lint test build Run lint, test, and build targets for affected projects. Requires Nx v15.4+
affected -t test --files=libs/mylib/src/index.ts Run tests for all the projects affected by changing the index.ts file
affected -t test --base=main --head=HEAD Run tests for all the projects affected by the changes between main and HEAD (e.g., PR)
affected -t test --base=main~1 --head=main Run tests for all the projects affected by the last commit on main
affected -t=build --exclude='*,!tag:dotnet' Run build for only projects with the tag `dotnet`
affected -t build --tag=$NX_TASK_TARGET_PROJECT:latest Use the currently executing project name in your command.
Find more information and examples at https://nx.dev/nx/affected
Error: Command failed: git diff --name-only --no-renames --relative "0000000000000000000000000000000000000000" "ba25f78f9628a757f1796feb00cd4dd4c2de2c68"
fatal: bad object 0000000000000000000000000000000000000000
at genericNodeError (node:internal/errors:984:15)
at wrappedFn (node:internal/errors:538:14)
at checkExecSyncError (node:child_process:890:11)
at execSync (node:child_process:962:15)
at parseGitOutput (/Users/baptistemahe/Documents/repos/unico-workspace/node_modules/nx/src/utils/command-line-utils.js:240:41)
at getFilesUsingBaseAndHead (/Users/baptistemahe/Documents/repos/unico-workspace/node_modules/nx/src/utils/command-line-utils.js:237:12)
at parseFiles (/Users/baptistemahe/Documents/repos/unico-workspace/node_modules/nx/src/utils/command-line-utils.js:191:20)
at getAffectedGraphNodes (/Users/baptistemahe/Documents/repos/unico-workspace/node_modules/nx/src/command-line/affected/affected.js:82:151)
at Object.affected (/Users/baptistemahe/Documents/repos/unico-workspace/node_modules/nx/src/command-line/affected/affected.js:34:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
status: 128,
signal: null,
output: [
null,
<Buffer >,
<Buffer 66 61 74 61 6c 3a 20 62 61 64 20 6f 62 6a 65 63 74 20 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 ... 9 more bytes>
],
pid: 22116,
stdout: <Buffer >,
stderr: <Buffer 66 61 74 61 6c 3a 20 62 61 64 20 6f 62 6a 65 63 74 20 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 ... 9 more bytes>
}
Failed
Output in nx@18.2.0:
$ npx nx affected:build --base="0000000000000000000000000000000000000000" --head="ba25f78f9628a757f1796feb00cd4dd4c2de2c68" --configuration="dev" || echo "Failed"
fatal: bad object 0000000000000000000000000000000000000000
NX Command failed: git diff --name-only --no-renames --relative "0000000000000000000000000000000000000000" "ba25f78f9628a757f1796feb00cd4dd4c2de2c68"
fatal: bad object 0000000000000000000000000000000000000000
Pass --verbose to see the stacktrace.
Anyone found any workaround for this?
I'm having a hard time replicating this issue. On my macbook at least, running nx affected --base FOO -t build
errors with code 1.
@BaptisteMahe you issue is caused by the || echo Failed
at the end. The echo command runs, indicating the first command exited with a non-zero code, but the whole command's status code is 0 due to how bash runs scripts.
@jsynacek Can you try to reproduce this with latest? If so, providing the exact command you see that doesn't fail would be helpful.
@AgentEnder I put the || echo Failed
at the end to show that the Failed
keyword appears in one case but not the other. If it appears it means that the nx
command exited with a non 0
code.
As shown in the output, this echo
command doesn't run on v18.2.0
.
Did you try with an nx version >= 18.2.0
?
I was trying with latest
This was causing me issues in a Github Action. The base commit didn't exists and therefore this threw an error. I fixed it by making sure it was included in the Checkout
The top of my action was:
- uses: actions/checkout@v4
name: Checkout [main]
Changed into:
- uses: actions/checkout@v4
name: Checkout [main]
with:
fetch-depth: 0
@jsynacek Can you try to reproduce this with latest?
I can confirm that this was fixed somewhere between v19.0.4 and v19.5.3. (Even though the exit code is 1 instead of whatever the exit code of the underlying command is, but that's ok I guess.)
$ npx nx --version
Nx Version:
- Local: v19.0.4
- Global: Not found
$ npx nx affected --base=IDONTEXIST -t test
fatal: ambiguous argument 'IDONTEXIST': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
NX Command failed: git diff --name-only --no-renames --relative "IDONTEXIST" "HEAD"
fatal: ambiguous argument 'IDONTEXIST': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Pass --verbose to see the stacktrace.
$ echo $?
0
$ npx nx --version
Nx Version:
- Local: v19.5.3
- Global: Not found
$ npx nx affected --base=IDONTEXIST -t test
fatal: ambiguous argument 'IDONTEXIST': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
NX Command failed: git diff --name-only --no-renames --relative "IDONTEXIST" "HEAD"
fatal: ambiguous argument 'IDONTEXIST': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Pass --verbose to see the stacktrace.
$ echo $?
1
This issue has been automatically marked as stale because no results of retrying on the latest version of Nx was provided within 7 days. It will be closed in 21 days if no results are provided. If the issue is still present, please reply to keep it active. If the issue was not present, please close this issue. Thanks for being a part of the Nx community! 🙏
Current Behavior
Here, the underlying
git
command clearly exists with an error.But the
nx affected
command exists with 0.Expected Behavior
The entire
nx affected
command should exit with whatever the underlying command exits with. In this particular case, it should be 128.GitHub Repo
No response
Steps to Reproduce
See the description.
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response