fix: prevent crash on invalid project directory

This commit is contained in:
CJ van den Berg 2025-08-13 12:08:24 +02:00
parent deee1afe13
commit 5b852fdb3d
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 4 additions and 2 deletions

View file

@ -27,7 +27,7 @@ const OutOfMemoryError = error{OutOfMemory};
const FileSystemError = error{FileSystem};
const SetCwdError = if (builtin.os.tag == .windows) error{UnrecognizedVolume} else error{};
const CallError = tp.CallError;
const ProjectManagerError = (SpawnError || error{ProjectManagerFailed});
const ProjectManagerError = (SpawnError || error{ ProjectManagerFailed, InvalidProjectDirectory });
pub fn get() SpawnError!Self {
const pid = tp.env.get().proc(module_name);
@ -63,6 +63,7 @@ pub fn open(rel_project_directory: []const u8) (ProjectManagerError || FileSyste
const project_directory = std.fs.cwd().realpath(rel_project_directory, &path_buf) catch "(none)";
const current_project = tp.env.get().str("project");
if (std.mem.eql(u8, current_project, project_directory)) return;
if (!root.is_directory(project_directory)) return error.InvalidProjectDirectory;
var dir = try std.fs.openDirAbsolute(project_directory, .{});
try dir.setAsCwd();
dir.close();