Skip to content

Commit ebea9a4

Browse files
spacetime dev - Improve error when module directory does not exist (#4467)
When `spacetime dev` (or `publish`) cannot find the module directory, the error was: ``` Error: Failed to build project Could not detect the language of the module. Are you in a SpacetimeDB project directory? ``` This is confusing because the real problem is the directory does not exist, not that the language cannot be detected. Now shows: ``` Module directory does not exist: '/path/to/missing/dir'. Check your --module-path flag or the module-path setting in spacetime.json. ``` Related to #4443. --------- Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com> Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com> Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
1 parent 1e6aa32 commit ebea9a4

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

crates/cli/src/util.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,29 @@ pub fn find_module_path(project_dir: &Path) -> Option<PathBuf> {
247247
None
248248
}
249249

250-
pub fn detect_module_language(path_to_project: &Path) -> anyhow::Result<ModuleLanguage> {
250+
pub fn detect_module_language(path_to_module: &Path) -> anyhow::Result<ModuleLanguage> {
251251
// TODO: Possible add a config file durlng spacetime init with the language
252+
if !path_to_module.exists() {
253+
anyhow::bail!(
254+
"Module directory does not exist: '{}'. \
255+
Check your --module-path flag or the module-path setting in spacetime.json.",
256+
path_to_module.display()
257+
);
258+
}
252259
// check for Cargo.toml
253-
if path_to_project.join("Cargo.toml").exists() {
260+
if path_to_module.join("Cargo.toml").exists() {
254261
Ok(ModuleLanguage::Rust)
255-
} else if path_to_project.is_dir()
256-
&& path_to_project
262+
} else if path_to_module.is_dir()
263+
&& path_to_module
257264
.read_dir()
258-
.map_err(|e| anyhow::anyhow!("Failed to read directory {}: {}", path_to_project.display(), e))?
265+
.map_err(|e| anyhow::anyhow!("Failed to read directory {}: {}", path_to_module.display(), e))?
259266
.flatten()
260267
.any(|entry| entry.path().extension() == Some("csproj".as_ref()))
261268
{
262269
Ok(ModuleLanguage::Csharp)
263-
} else if path_to_project.join("package.json").exists() {
270+
} else if path_to_module.join("package.json").exists() {
264271
Ok(ModuleLanguage::Javascript)
265-
} else if path_to_project.join("CMakeLists.txt").exists() {
272+
} else if path_to_module.join("CMakeLists.txt").exists() {
266273
Ok(ModuleLanguage::Cpp)
267274
} else {
268275
anyhow::bail!("Could not detect the language of the module. Are you in a SpacetimeDB project directory?")

0 commit comments

Comments
 (0)