Skip to content

fix: avoid panic when current working directory no longer exists#5652

Merged
baszalmstra merged 2 commits intoprefix-dev:mainfrom
mohitdebian:fix-cwd-panic
Mar 13, 2026
Merged

fix: avoid panic when current working directory no longer exists#5652
baszalmstra merged 2 commits intoprefix-dev:mainfrom
mohitdebian:fix-cwd-panic

Conversation

@mohitdebian
Copy link
Contributor

Description

Fix a panic that occurs when Pixi is run from a working directory that no longer exists.

Previously, std::env::current_dir() was called with .expect("Could not retrieve the current directory") in default_channel_config(). If the working directory had been deleted, this would cause Pixi to panic.

This change replaces the .expect() call with a non-panicking fallback:

let cwd = std::env::current_dir()
    .unwrap_or_else(|_| std::path::PathBuf::from("."));
ChannelConfig::default_with_root_dir(cwd)

This prevents the panic and allows Pixi to return a proper CLI error instead of crashing.

Fixes #5639

How Has This Been Tested?

The issue was reproduced using the steps provided in the report:

mkdir tmp
cd tmp
pixi init
pixi task add hello echo
pixi run hello

In another shell:

rm -rf tmp

Back in the original shell:

pixi run hello

Before this change, Pixi would panic. After this change, Pixi exits gracefully with an error message indicating that the current directory cannot be determined.

The project was also built and tested locally:

cargo build
cargo test

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added sufficient tests to cover my changes.
  • I have verified that changes that would impact the JSON schema have been made in schema/model.py.

@mohitdebian mohitdebian requested a review from baszalmstra March 11, 2026 17:09
@baszalmstra baszalmstra enabled auto-merge (squash) March 13, 2026 10:25
@baszalmstra baszalmstra merged commit a4665db into prefix-dev:main Mar 13, 2026
70 of 71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panicking when trying to run a task in a directory that no longer exists

2 participants