From 89df01f829ea680fcd6846eddbc4600610aba103 Mon Sep 17 00:00:00 2001 From: Piepmatz Date: Sat, 24 May 2025 21:11:26 +0200 Subject: [PATCH] Provide a better error for prefix-only path for PWD (#15817) --- crates/nu-protocol/src/engine/stack.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/nu-protocol/src/engine/stack.rs b/crates/nu-protocol/src/engine/stack.rs index a04968887c..cd1add986e 100644 --- a/crates/nu-protocol/src/engine/stack.rs +++ b/crates/nu-protocol/src/engine/stack.rs @@ -9,6 +9,7 @@ use nu_utils::IgnoreCaseExt; use std::{ collections::{HashMap, HashSet}, fs::File, + path::{Component, MAIN_SEPARATOR}, sync::Arc, }; @@ -755,6 +756,19 @@ impl Stack { let path = path.as_ref(); if !path.is_absolute() { + if matches!(path.components().next(), Some(Component::Prefix(_))) { + return Err(ShellError::GenericError { + error: "Cannot set $env.PWD to a prefix-only path".to_string(), + msg: "".into(), + span: None, + help: Some(format!( + "Try to use {}{MAIN_SEPARATOR} instead", + path.display() + )), + inner: vec![], + }); + } + error("Cannot set $env.PWD to a non-absolute path") } else if !path.exists() { error("Cannot set $env.PWD to a non-existent directory")