properly handle errors in karen's eval packet handling + add exec packet
@@ -55,10 +55,19 @@ class MechaKaren:
result = eval(packet.code, self.eval_env)
success = True
except Exception as e:
- result = str(e)
+ result = repr(e)
success = False
await stream.write_packet({"type": "eval-response", "id": packet.id, "result": result, "success": success})
+ elif packet.type == "exec":
+ try:
+ result = await execute_code(packet.code, self.eval_env)
+ success = True
+ except Exception as e:
+ result = repr(e)
+ success = False
+
+ await stream.write_packet({"type": "exec-response", "id": packet.id, "result": result, "success": success})
elif packet.type == "broadcast-request":
# broadcasts the packet to every connection including the broadcaster, and waits for responses
broadcast_id = f"b{self.current_id}"
