conda-forge / conda-forge/libxml2-feedstock

activate.ps1 references non-existing variable

Open
#173 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Shell
Stars
3
Forks
42
Avg merge
29m
Merged PRs (30d)
1

Description

### Solution to issue cannot be found in the documentation.

- [x] I checked the documentation.

### Issue

https://github.com/conda-forge/libxml2-feedstock/blob/main/recipe/activate.ps1 contains

```
$conda_catalog_files += "file:///" + $Env:CONDA_PREFIX.replace(" ", "%20").replace("\", "/") + "/etc/xml/catalog"
```

which will fail with [PS strict mode](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode?view=powershell-7.5) turned on because the variable `$conda_catalog_files` does not exist:

```
InvalidOperation: activate.ps1:9
Line |
9 | $conda_catalog_files += "file:///" + $Env:CONDA_PREFIX.replace(" ", " …
| ~~~~~~~~~~~~~~~~~~~~
| The variable '$conda_catalog_files' cannot be retrieved because it has not been set.
```

Strict mode is not uncommon so would be good to fix this by guarding `$conda_catalog_files`.

However I'm not sure if this variable is actually needed: what is the intent of this code? Where does it expect the `$conda_catalog_files` variable to come from such that it needs appending to? In https://github.com/conda-forge/libxml2-feedstock/commit/d94514357626a48e0ee4af7e3f22b61935a781bd the `+` was added but that was maybe not actually intended. So I'm wondering if all that is needed here is just to remove that line and use this instead

```
$Env:XML_CATALOG_FILES += "file:///" + $Env:CONDA_PREFIX.replace(" ", "%20").replace("\", "/") + "/etc/xml/catalog"
```

Also note that because of replacing spaces with `%20` this actually changes from a valid file path to something URL-like, but that's probably wanted?

### Installed packages

```shell
Not relevant, this concerns libxml2 only.
```

### Environment info

```shell
platform : win-64
user-agent : conda/4.12.0 requests/2.32.3 CPython/3.9.18 Windows/10 Windows/10.0.19045
administrator : False
netrc file : None
offline mode : False
```

Contributor guide

Open the contributing guide

Research direction

Start with recipe/activate.ps1 and reproduce the failure with PowerShell strict mode enabled. Trace how the catalog-file variable and XML_CATALOG_FILES environment variable are used, then confirm the activation script no longer references an unset variable and still configures the intended catalog path.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.