fix: prevent crash on invalid project directory
This commit is contained in:
parent
deee1afe13
commit
5b852fdb3d
3 changed files with 4 additions and 2 deletions
|
@ -27,7 +27,7 @@ const OutOfMemoryError = error{OutOfMemory};
|
||||||
const FileSystemError = error{FileSystem};
|
const FileSystemError = error{FileSystem};
|
||||||
const SetCwdError = if (builtin.os.tag == .windows) error{UnrecognizedVolume} else error{};
|
const SetCwdError = if (builtin.os.tag == .windows) error{UnrecognizedVolume} else error{};
|
||||||
const CallError = tp.CallError;
|
const CallError = tp.CallError;
|
||||||
const ProjectManagerError = (SpawnError || error{ProjectManagerFailed});
|
const ProjectManagerError = (SpawnError || error{ ProjectManagerFailed, InvalidProjectDirectory });
|
||||||
|
|
||||||
pub fn get() SpawnError!Self {
|
pub fn get() SpawnError!Self {
|
||||||
const pid = tp.env.get().proc(module_name);
|
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 project_directory = std.fs.cwd().realpath(rel_project_directory, &path_buf) catch "(none)";
|
||||||
const current_project = tp.env.get().str("project");
|
const current_project = tp.env.get().str("project");
|
||||||
if (std.mem.eql(u8, current_project, project_directory)) return;
|
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, .{});
|
var dir = try std.fs.openDirAbsolute(project_directory, .{});
|
||||||
try dir.setAsCwd();
|
try dir.setAsCwd();
|
||||||
dir.close();
|
dir.close();
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub const Error = (cbor.Error || cbor.JsonEncodeError || error{
|
||||||
ThespianSpawnFailed,
|
ThespianSpawnFailed,
|
||||||
NoProject,
|
NoProject,
|
||||||
ProjectManagerFailed,
|
ProjectManagerFailed,
|
||||||
|
InvalidProjectDirectory,
|
||||||
SendFailed,
|
SendFailed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -322,6 +322,7 @@ const cmds = struct {
|
||||||
if (!try ctx.args.match(.{tp.extract(&project_dir)}))
|
if (!try ctx.args.match(.{tp.extract(&project_dir)}))
|
||||||
return;
|
return;
|
||||||
try self.check_all_not_dirty();
|
try self.check_all_not_dirty();
|
||||||
|
try project_manager.open(project_dir);
|
||||||
for (self.editors.items) |editor| {
|
for (self.editors.items) |editor| {
|
||||||
editor.clear_diagnostics();
|
editor.clear_diagnostics();
|
||||||
try editor.close_file(.{});
|
try editor.close_file(.{});
|
||||||
|
@ -332,7 +333,6 @@ const cmds = struct {
|
||||||
try self.toggle_panel_view(filelist_view, false);
|
try self.toggle_panel_view(filelist_view, false);
|
||||||
self.buffer_manager.deinit();
|
self.buffer_manager.deinit();
|
||||||
self.buffer_manager = Buffer.Manager.init(self.allocator);
|
self.buffer_manager = Buffer.Manager.init(self.allocator);
|
||||||
try project_manager.open(project_dir);
|
|
||||||
const project = tp.env.get().str("project");
|
const project = tp.env.get().str("project");
|
||||||
tui.rdr().set_terminal_working_directory(project);
|
tui.rdr().set_terminal_working_directory(project);
|
||||||
if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
|
if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue