Bail and signal error when the cwd of a resolved task doesn't exist (#32777)
Closes #32688 Release Notes: - Fixed tasks (including build tasks for debug configurations) silently using `/` as a working directory when the specified `cwd` didn't exist.
This commit is contained in:
parent
0f0ff40c6d
commit
22a2ff4f12
6 changed files with 54 additions and 4 deletions
|
@ -29,6 +29,7 @@ serde_json.workspace = true
|
|||
serde_json_lenient.workspace = true
|
||||
sha2.workspace = true
|
||||
shellexpand.workspace = true
|
||||
smol.workspace = true
|
||||
util.workspace = true
|
||||
workspace-hack.workspace = true
|
||||
zed_actions.workspace = true
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use anyhow::{Context as _, bail};
|
||||
use anyhow::{Context as _, Result, anyhow, bail};
|
||||
use collections::{HashMap, HashSet};
|
||||
use gpui::{BackgroundExecutor, Task};
|
||||
use schemars::{JsonSchema, r#gen::SchemaSettings};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
@ -270,6 +271,27 @@ impl TaskTemplate {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
pub fn resolve_task_and_check_cwd(
|
||||
&self,
|
||||
id_base: &str,
|
||||
task_context: &TaskContext,
|
||||
executor: BackgroundExecutor,
|
||||
) -> Option<Task<Result<ResolvedTask>>> {
|
||||
let resolved_task = self.resolve_task(id_base, task_context)?;
|
||||
let task = executor.spawn(async move {
|
||||
if let Some(cwd) = resolved_task.resolved.cwd.as_deref() {
|
||||
match smol::fs::metadata(cwd).await {
|
||||
Ok(metadata) if metadata.is_dir() => Ok(resolved_task),
|
||||
Ok(_) => Err(anyhow!("cwd for resolved task is not a directory: {cwd:?}")),
|
||||
Err(e) => Err(e).context(format!("reading cwd of resolved task: {cwd:?}")),
|
||||
}
|
||||
} else {
|
||||
Ok(resolved_task)
|
||||
}
|
||||
});
|
||||
Some(task)
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_DISPLAY_VARIABLE_LENGTH: usize = 15;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue