diff --git a/misskaty/plugins/dev.py b/misskaty/plugins/dev.py index 1218cc3a..33528e97 100644 --- a/misskaty/plugins/dev.py +++ b/misskaty/plugins/dev.py @@ -1,6 +1,7 @@ import asyncio import io import os +import re import sys import pickle import traceback @@ -156,12 +157,38 @@ async def evaluation_cmd_t(_, m): try: await aexec(cmd, _, m) - except Exception: - # exc = traceback.format_exc(limit=4) - exc_type, exc_value, exc_tb = sys.exc_info() - tb = traceback.TracebackException(exc_type, exc_value, exc_tb) - exc = f"{exc_type} {exc_value} {exc_tb}\n\n{tb}" - # print(''.join(tb.format_exception_only())) + except NameError as e: + trace_output = "❌ MISSING VARIABEL:\n" + trace_output += f"{e}" + exc = trace_output + except AttributeError as e: + trace_output = "❌ MISSING ATTRIBUTE:\n" + trace_output += f"{e}" + exc = trace_output + except SyntaxError as e: + trace = traceback.format_exc() + splitted = str(trace).split("\n") + end_split = len(splitted) + row_1 = splitted[end_split - 4] + row_2 = splitted[end_split - 3] + row_3 = splitted[end_split - 2] + compiles = row_1 + "\n" + row_2 + "\n" + row_3 + trace_output = "⚙️ SYNTAX ERROR:\n" + trace_output += f"{compiles}" + exc = trace_output + except ValueError as e: + trace_output = "🧮 VALUE ERROR:\n" + trace_output += f"{e}" + exc = trace_output + except Exception as e: + #trace = traceback.format_exc() + """ Periksa apakah error regexnya tertangkap""" + match = re.search(r"Telegram says: .+", str(e)) + trace_output = "⚠️ COMMON ERROR:\n" + trace_output += f"{e}" + if match: + trace_output = f"👀 {match[0]}" + exc = trace_output stdout = redirected_output.getvalue() stderr = redirected_error.getvalue()