Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opam var XXX fails when no switch is selected #5025

Closed
Khady opened this issue Jan 25, 2022 · 2 comments · Fixed by #5027
Closed

opam var XXX fails when no switch is selected #5025

Khady opened this issue Jan 25, 2022 · 2 comments · Fixed by #5027

Comments

@Khady
Copy link
Contributor

Khady commented Jan 25, 2022

When no switch is selected, for example because I don't have a global switch and I'm not in a folder with a local switch, the command opam var and all the sub commands are returning an error code 50.

~$ opam init --bare
~$ cd ~/project-with-local-switch
~/project-with-local-switch$ opam sw create . 4.12.1 --no-install
~$ cd
~$ opam var; echo $?

<><> Global opam variables ><><><><><><><><><><><><><><><><><><><><><><><><><><>
arch              x86_64                  # Inferred from system
exe                                       # Suffix needed for executable filenames (Windows)
jobs              255                     # The number of parallel jobs set up in opam configuration
make              make                    # The 'make' command to use
opam-version      2.1.2                   # The currently running opam version
os                linux                   # Inferred from system
os-distribution   debian                  # Inferred from system
os-family         debian                  # Inferred from system
os-version        10                      # Inferred from system
root              /home/louis.roche/.opam # The current opam root directory
switch                                    # The identifier of the current switch
sys-ocaml-arch                            # Target architecture of the OCaml compiler present on your system
sys-ocaml-cc                              # Host C Compiler type of the OCaml compiler present on your system
sys-ocaml-libc                            # Host C Runtime Library type of the OCaml compiler present on your system
sys-ocaml-version                         # OCaml version present on your system independently of opam, if any

<><> Configuration variables from the current switch ><><><><><><><><><><><><><>
[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch
50
~$ opam var root; echo $?
[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch
50
~$ cd ~/project-with-local-switch
~/project-with-local-switch$ opam var root; echo $?
/home/louis.roche/.opam
0

That's with opam version 2.1.2. With 2.0.8 the behavior was different from what I could reproduce and opam config var root wouldn't return an error.

ocamllabs/vscode-ocaml-platform#701

@kit-ty-kate
Copy link
Member

As a workaround opam var --global root works without a switch

@rjbou rjbou added this to the 2.2.0~alpha milestone Jan 25, 2022
@rjbou
Copy link
Collaborator

rjbou commented Jan 25, 2022

Digging & fixing that, i found another bug : setting an option on a non-existent switch don't fail and write the switch config file! It leads to opam internals to be inconsistent 😨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants