pkgx icon indicating copy to clipboard operation
pkgx copied to clipboard

unexpected error cannot intersect: @1.6.4 && @1.5.4

Open kishaningithub opened this issue 2 years ago • 15 comments

Getting the following error in a random fashion as i move through terraform codebases

Error

$ terraform fmt -recursive
× unexpected error cannot intersect: @1.6.4 && @1.5.4
│ Error: cannot intersect: @1.6.4 && @1.5.4
│     at Module.intersect (https://deno.land/x/[email protected]/src/utils/semver.ts:382:30)
│     at condense (https://deno.land/x/[email protected]/src/plumbing/hydrate.ts:78:33)
│     at hydrate (https://deno.land/x/[email protected]/src/plumbing/hydrate.ts:13:15)
│     at file:///Users/builder/actions-runner/_work/pkgx/pkgx/src/prefab/install.ts:10:60
│     at failsafe (file:///Users/builder/actions-runner/_work/pkgx/pkgx/src/prefab/failsafe.ts:5:18)
│     at default (file:///Users/builder/actions-runner/_work/pkgx/pkgx/src/prefab/install.ts:10:47)
│     at eventLoopTick (ext:core/01_core.js:178:11)
│     at async default (file:///Users/builder/actions-runner/_work/pkgx/pkgx/src/modes/x.ts:30:18)
│     at async default (file:///Users/builder/actions-runner/_work/pkgx/pkgx/src/app.ts:48:11)
│     at async file:///Users/builder/actions-runner/_work/pkgx/pkgx/entrypoint.ts:59:3
╰─➤ https://github.com/pkgxdev/pkgx/issues/new

Workaround

Do dev off and then run dev

kishaningithub avatar Dec 20 '23 11:12 kishaningithub

the only package.yml I see that mentions 1.5.4 is github.com/moretension/duti; none mention 1.6.4 that i can find. what is in your pkgx.yml or .terraform-version file?

likely this is a case of trying to get multiple different terraforms into the same env. iirc, there's a very subtle bug where moving from one dev env to another doesn't always work cleanly, so that is likely what you're hitting.

jhheider avatar Dec 20 '23 16:12 jhheider

I am using only the .terraform-version file. The content of that would vary from one project folder to another (example below) and i keep switching between projects all through the day.

Project A

$ cat .terraform-version
1.6.4

Project B

$ cat .terraform-version
1.5.4

Project C

$ cat .terraform-version
0.13.7

kishaningithub avatar Dec 22 '23 10:12 kishaningithub

so, I think this is the changing from one dev env to the other issue. i can think of two workarounds:

  • dev off; dev <- should reset everything
  • cd ~; cd new/folder <- should do likewise

jhheider avatar Dec 22 '23 19:12 jhheider

Any ideas to fix this at a code level ? I can try contributing a PR for this

kishaningithub avatar Dec 23 '23 04:12 kishaningithub

Most likely the chdir hook in the shell needs to unload-then-load, but that could cause overhead, as well as deps changing in rare instances.

jhheider avatar Dec 23 '23 06:12 jhheider

basically this code needs to know if it's going from one dev-env to another, rather than within a single dev-env. your test case looks something like this:

mkdir -p a/b a/c
echo -e "dependencies:\n  llvm.org: ^15" >a/pkgx.yml
echo -e "dependencies:\n  llvm.org: ^16" >a/b/pkgx.yml
cd a
dev
test "$(clang --version)" | grep "version 15"
cd b
test "$(clang --version)" | grep "version 16"
cd c
test "$(clang --version)" | grep "version 15"
cd b
test "$(clang --version)" | grep "version 16"
cd ..
test "$(clang --version)" | grep "version 15"
cd c
test "$(clang --version)" | grep "version 15"

i think.

jhheider avatar Dec 24 '23 00:12 jhheider

I hit this too today, I would think it's related, but otherwise I'll open another issue. Tried to run pkgx psql in a folder with some packages already, and got:

$ env +psql
× unexpected error cannot intersect: ^71 && ^73
│ Error: cannot intersect: ^71 && ^73
│     at Module.intersect (https://deno.land/x/[email protected]/src/utils/semver.ts:384:30)
│     at hydrate (https://deno.land/x/[email protected]/src/plumbing/hydrate.ts:51:48)
│     at eventLoopTick (ext:core/01_core.js:181:11)
│     at async failsafe (file:///Users/runner/work/pkgx/pkgx/src/prefab/failsafe.ts:5:12)
│     at async default (file:///Users/runner/work/pkgx/pkgx/src/prefab/install.ts:10:41)
│     at async default (file:///Users/runner/work/pkgx/pkgx/src/modes/internal.use.ts:16:20)
│     at async default (file:///Users/runner/work/pkgx/pkgx/src/app.ts:65:20)
│     at async file:///Users/runner/work/pkgx/pkgx/entrypoint.ts:59:3
╰─➤ https://github.com/pkgxdev/pkgx/issues/new

Output of env:

PKGX_POWDER=nodejs.org^18 git-scm.org pkgx.sh
PKGX_PKGENV=curl.se/ca-certs=2023.8.22 gnome.org/libxml2=2.11.4 tukaani.org/xz=5.4.5 unicode.org=71.1.0 openssl.org=1.1.1w zlib.net=1.3.0 gnu.org/gettext=0.21.1 curl.se=8.3.0 perl.org=5.38.0 libexpat.github.io=2.5.0 nodejs.org=18.18.0 npmjs.com=9.9.0 git-scm.org=2.42.0 pkgx.sh=1.1.4

pkgx.yaml:

dependencies:
  nodejs.org: 18
  npmjs.com: 9

jakobvase avatar Jan 11 '24 12:01 jakobvase

As i am getting this error very frequently, as a workaround i have added the following line to my ~/.zshrc which makes the problem disappear

dev off && dev

kishaningithub avatar Jan 24 '24 06:01 kishaningithub

Sorry for this everyone. I’m actively figuring out solutions now.

mxcl avatar Jan 24 '24 22:01 mxcl

K so this particular problem is in the dev shellcode. The unicode.org issue (^71 && ^73) is separate

mxcl avatar Jan 24 '24 22:01 mxcl

How do I reproduce this?

I created two directories added .terraform-version files with 1.6.4 and 1.5.4 in. Then dev in each then cd ../other and don’t get any issues.

image

mxcl avatar Jan 24 '24 22:01 mxcl

I've updated to the latest version, and I can't reproduce it anymore. In my case, I think it was caused by a pkgx.yaml with node 18 and {"engines": {"node": ">=20.0.0 < 21.0.0"}} in package.json.

When I try to dev in that directory, I get × invalid constraint for nodejs.org: undefined. And then when I try to dev off I get cmd not found: _pkgx_dev_off. Maybe it's all unrelated.

reproduce-pkgx $ pkgx --version
pkgx 1.1.5

jakobvase avatar Jan 25 '24 08:01 jakobvase

The unicode issue is fixed in pkgx 1.1.6. The terraform one I cannot reproduce. @jakobvase yes asking for both node 18 and 20 would be a conflict, the other issues are separate bugs we should fix. I believe the constraint you specified is not supported by our semver range parser and the dev off error is just bad: it should say “no dev env” probs.

mxcl avatar Jan 28 '24 15:01 mxcl

@mxcl I found the reason for my issue :-)

It was due to a terraform binary present in the path (~/.local/bin/terraform) installed using pkgx install [email protected] command conflicting with version specified in the .terraform-version file of the project

Prerequisites

  • Ensure to have an iterm2 setup where you have enabled "Reuse previous session's directory" (screenshot below) Screenshot 2024-01-29 at 3 54 22 PM

Steps for simulation

  1. Install terraform using pkgx install [email protected]
  2. Create a terraform project mkdir -p terraform-repo && echo "1.6.4" > terraform-repo/.terraform-version
  3. cd terraform-repo
  4. dev
  5. Run terraform version - This will print out the right version (1.6.4) in the console without any errors
  6. Press "Cmd + D" to create a tab pane which will initialize with the same current working directory and type terraform version (screenshot below) image

kishaningithub avatar Jan 29 '24 10:01 kishaningithub

Having a terraform binary in PATH will not cause this issue.

A conflict is only possible if an existing pkg-env is present when trying to change that env. That environment is controlled by the PKGX_PKGENV environment variable and not by the presence of other programs in the PATH.

Is it possible that iTerm2 is preserving PKGX_PKGENV between sessions? Is it possible that you have a .terraform-version file in a higher directory that has also been enabled by typing dev?

mxcl avatar Jan 30 '24 12:01 mxcl