Skip to content

conda hooks disturb PowerShell error status #11058

@vdsbenoit

Description

@vdsbenoit

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a solution or duplication
  • I already searched in Google and didn't find any good information or help
  • I looked at the docs and didn't see anything to help

What happened?

Issue

Description

I noticed that the conda hooks for PowerShell have a side effect on the error status of the subsequent conda commands. The command echo $? returns True to every conda commands, whatever the error status is.

Is it bad ?

Yes. PowerShell does not care about the value of the $LastExitCode variable value; it keeps on processing commands even though the $LastExitCode is not 0. Only the error status of the previous command is taken into account by PowerShell.

On CI systems that run on PowerShell (e.g. GitLab), this behavior is problematic. For instance, I see some of my conda build CI jobs passing while, after reading the log, I see that the tests failed. The CI jobs continued because the conda build command returned a True error status even though the tests were failing.

Demonstration

In order to assert the statement here above, I performed this test : I commented the command that run the conda hooks in my PowerShell profile (~/Documents/PowerShell/profile.ps1). This command was added during the conda init process.

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
# (& "C:\Miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion

Then, I opened a terminal and I ran the same commands twice. Once before running the conda hooks, once after running them.

Expected behavior (before conda hooks)

PS > conda --foo
usage: conda-script.py [-h] [-V] command ...
conda-script.py: error: the following arguments are required: command
PS > echo $?
False

Actual behavior (after conda hooks)

Here, I manually run the conda hooks command then repeat the same steps.

PS > (& "C:\Miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
PS > conda --foo
usage: conda-script.py [-h] [-V] command ...
conda-script.py: error: the following arguments are required: command
PS > echo $?
True

Conda info

Click to expand
PS > conda info

     active environment : base
    active env location : C:\Miniconda3
            shell level : 1
       user config file : C:\Users\vdsbenoit\.condarc
 populated config files : C:\Miniconda3\.condarc
                          C:\Users\vdsbenoit\.condarc
          conda version : 4.10.3
    conda-build version : not installed
         python version : 3.9.7.final.0
       virtual packages : __cuda=11.5=0
                          __win=0=0
                          __archspec=1=x86_64
       base environment : C:\Miniconda3  (writable)
      conda av data dir : C:\Miniconda3\etc\conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : C:\Miniconda3\pkgs
                          C:\Users\vdsbenoit\.conda\pkgs
                          C:\Users\vdsbenoit\AppData\Local\conda\conda\pkgs
       envs directories : C:\Miniconda3\envs
                          C:\Users\vdsbenoit\.conda\envs
                          C:\Users\vdsbenoit\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.10.3 requests/2.26.0 CPython/3.9.7 Windows/10 Windows/10.0.19043
          administrator : False
             netrc file : None
           offline mode : False

Conda config

Click to expand
PS > conda config --show-sources
==> C:\Miniconda3\.condarc <==
channels:
  - conda-forge

==> C:\Users\vdsbenoit\.condarc <==
envs_dirs:
  - C:\Miniconda3\envs

Conda list

Click to expand
PS > conda list --show-channel-urls
# packages in environment at C:\Miniconda3:
#
# Name                    Version                   Build  Channel
bottle                    0.12.19                  pypi_0    pypi
brotlipy                  0.7.0           py39hb82d6ee_1001    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2021.10.8            h5b45459_0    conda-forge
certifi                   2021.10.8        py39hcbf5309_0    conda-forge
cffi                      1.14.6           py39h0878f49_1    conda-forge
chardet                   4.0.0            py39hcbf5309_1    conda-forge
charset-normalizer        2.0.0              pyhd8ed1ab_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
conan                     1.42.0                   pypi_0    pypi
conda                     4.10.3           py39hcbf5309_2    conda-forge
conda-package-handling    1.7.3            py39hb3671d1_0    conda-forge
cryptography              3.4.7            py39hd8d06c1_0    conda-forge
distro                    1.6.0                    pypi_0    pypi
fasteners                 0.16.3                   pypi_0    pypi
idna                      3.1                pyhd3deb0d_0    conda-forge
jinja2                    2.11.3                   pypi_0    pypi
krb5                      1.19.2               hbae68bd_2    conda-forge
libarchive                3.5.2                hb45042f_1    conda-forge
libcurl                   7.79.1               h789b8ee_1    conda-forge
libiconv                  1.16                 he774522_0    conda-forge
libsolv                   0.7.19               h7755175_5    conda-forge
libssh2                   1.10.0               h680486a_2    conda-forge
libxml2                   2.9.12               hf5bbc77_0    conda-forge
libzlib                   1.2.11            h8ffe710_1013    conda-forge
lz4-c                     1.9.3                h8ffe710_1    conda-forge
lzo                       2.10              he774522_1000    conda-forge
mamba                     0.16.0           py39h006a82b_0    conda-forge
markupsafe                2.0.1                    pypi_0    pypi
menuinst                  1.4.18           py39hcbf5309_0    conda-forge
miniforge_console_shortcut 1.0                  h57928b3_0    conda-forge
node-semver               0.6.1                    pypi_0    pypi
openssl                   1.1.1l               h8ffe710_0    conda-forge
patch-ng                  1.17.4                   pypi_0    pypi
pip                       21.3               pyhd8ed1ab_0    conda-forge
pluginbase                1.0.1                    pypi_0    pypi
pycosat                   0.6.3           py39hb82d6ee_1006    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pygments                  2.10.0                   pypi_0    pypi
pyjwt                     1.7.1                    pypi_0    pypi
pyopenssl                 20.0.1             pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1            py39hcbf5309_3    conda-forge
python                    3.9.7           h7840368_2_cpython    conda-forge
python-dateutil           2.8.2                    pypi_0    pypi
python_abi                3.9                      2_cp39    conda-forge
pywin32                   301              py39hb82d6ee_0    conda-forge
pyyaml                    5.4.1                    pypi_0    pypi
reproc                    14.2.3               h8ffe710_0    conda-forge
reproc-cpp                14.2.3               h0e60522_0    conda-forge
requests                  2.26.0             pyhd8ed1ab_0    conda-forge
ruamel_yaml               0.15.80         py39hb82d6ee_1004    conda-forge
setuptools                58.0.4           py39hcbf5309_2    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.36.0               h8ffe710_2    conda-forge
tk                        8.6.11               h8ffe710_1    conda-forge
tqdm                      4.62.3             pyhd8ed1ab_0    conda-forge
tzdata                    2021a                he74cb21_1    conda-forge
ucrt                      10.0.20348.0         h57928b3_0    conda-forge
urllib3                   1.26.7             pyhd8ed1ab_0    conda-forge
vc                        14.2                 hb210afc_5    conda-forge
vs2015_runtime            14.29.30037          h902a5da_5    conda-forge
wheel                     0.37.0             pyhd8ed1ab_1    conda-forge
win_inet_pton             1.1.0            py39hcbf5309_2    conda-forge
xz                        5.2.5                h62dcd97_1    conda-forge
yaml                      0.2.5                he774522_0    conda-forge
zlib                      1.2.11            h8ffe710_1013    conda-forge
zstd                      1.5.0                h6255e5f_0    conda-forge

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogissue has been triaged but has not been earmarked for any upcoming releasecli::powershellpertains to the CLI in PowerShelllocked[bot] locked due to inactivityseverity::2critical; broken functionality with an unacceptably complex workaroundsource::communitycatch-all for issues filed by community membersstale[bot] marked as stale due to inactivitystale::closed[bot] closed after being marked as staletype::bugdescribes erroneous operation, use severity::* to classify the type

    Type

    No type

    Projects

    Status

    🏁 Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions