diff options
Diffstat (limited to 'src/edit_cmd.zig')
| -rw-r--r-- | src/edit_cmd.zig | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig index b1239a84..f299a39d 100644 --- a/src/edit_cmd.zig +++ b/src/edit_cmd.zig @@ -198,7 +198,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { } } if (res.undo != 0) { - for (0..@abs(res.undo)) |_| panes.File.undoStep(p, pane, res.undo > 0); + for (0..@abs(res.undo)) |_| panes.File.undoStep(p, pane, res.undo > 0) catch |err| return p.reportError(id, "Edit", err); return; } pd.res = res; @@ -357,9 +357,8 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { // back with the old text, and it leaves the pane clean. for (res.files) |f| { const path = f.get orelse continue; - var failed: anyerror = error.Unexpected; - const errno = @import("ninep/ctl.zig").getFile(p, p.panes[f.id].?, path, &failed); - if (errno != 0) return p.reportFailure(at, text.print("Edit: e {s}: {s}", .{ path[0..@min(path.len, 256)], if (errno == @import("ninep/tree.zig").E.NOENT) "no such file" else "cannot be read" })); + @import("ninep/ctl.zig").getFile(p, p.panes[f.id].?, path) catch |err| + return p.reportFailure(at, text.print("Edit: e {s}: {s}", .{ path[0..@min(path.len, 256)], if (err == error.FileNotFound) "no such file" else "cannot be read" })); } // `w`'s bytes, written after this step, before anything else is. To // its own file changed on disk since it was read, as Save is: refused @@ -410,7 +409,10 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { const new = sam.apply(p.gpa, pf.content, ops) catch |err| return p.reportError(at, "Edit", err); // `s/a/a/` changes nothing: no undo step, no new revision. if (std.mem.eql(u8, new, pf.content)) p.gpa.free(new) else { - panes.File.pushUndo(p, pane); + panes.File.pushUndo(p, pane) catch |err| { + p.gpa.free(new); + return p.reportError(at, "Edit", err); + }; panes.File.setContent(p, pf, new); } } |
