added useful exception info to ed

This commit is contained in:
Luxferre
2025-12-21 11:36:08 +02:00
parent 4c9195a7cc
commit dbfaaeb4c9
+5 -5
View File
@@ -162,7 +162,7 @@ class Ed:
sep = params[0] sep = params[0]
parts = params.split(sep) parts = params.split(sep)
if len(parts) < 3: if len(parts) < 3:
print("?") print("Invalid s/old/new syntax")
continue continue
old, new = parts[1], parts[2] old, new = parts[1], parts[2]
start = max(1, start) start = max(1, start)
@@ -176,7 +176,7 @@ class Ed:
elif cmd_char == 'w': elif cmd_char == 'w':
target = params if params else self.filename target = params if params else self.filename
if not target: if not target:
print("?") print("No target file to write to")
continue continue
with open(target, "w") as f: with open(target, "w") as f:
for line in self.buffer: for line in self.buffer:
@@ -191,10 +191,10 @@ class Ed:
print(self.filename if self.filename else "No current filename") print(self.filename if self.filename else "No current filename")
else: else:
print("?") print("Unknown command")
except Exception: except Exception as e:
print("?") print(f"Exception occurred: {e}")
def edit(fname): def edit(fname):
editor = Ed(fname) editor = Ed(fname)