So I have a file of errors, there default meanings and also it's hierarchy in terms of indentation
BaseException General for all errors of any and every kind.
SystemExit Called for when the system wants to exit.
KeyboardInterrupt Called when an operator interrupts an action.
GeneratorExit Called when the system requests a generator exit.
Exception General for all non-exit errors.
StopIteration Called when an iterator ended unexpectedly.
StopAsyncIteration Called when an asynchronous iterator ended unexpectedly.
ArithmeticError General for arithmetic errors.
FloatingPointError Called when interpreting a float failed.
OverflowError Called when the result was too large to be represented.
ZeroDivisionError Called when dividing by zero. Contrary to belief, it does not blow up the entire system. Atleast- not all the time.
AssertionError Called when an assertion fails.
And I have then converted it all into a list of tuples, with a searcher function along with it such that error("ArithmeticError"), error("007") and error(7) all return
[
1,
"007",
"ArithmeticError",
"General for arithmetic errors.",
[
0,
"004",
"Exception",
"General for all non-exit errors.",
[
0,
"000",
"BaseException",
"General for all errors of any and every kind."
],
]
]
Which is the data from before in the format
[
indentation (number of spaces before words),
code (line it is on),
name (first word),
default reason (all words but the first),
[
parents indentation
parents code
parents name
parents default reason
parents parent (if it exists)
[
]
All errors will have a parent apart from BaseException (000) This is the code I have done for it, but I feel like there is a more effecient method.
import os,builtlins
def r(p,b="default"): #r("cache/errors.log") returns path_to_project_root_folder/cache/errors.logs
b,p=b.replace("\\","/"),p.replace("\\","/");p=p if p.startswith("/") else f"/{p}"
return ((resourcepath if b=="default" else (b[:len(b)-1] if p.startswith("/") and b.endswith("/") else b))+(p[:len(p)-1] if p.endswith("/") else p)).replace("/","\\").replace("\\\\","\\")
resourcepath=os.getcwd()[:os.getcwd().find("Ancilla Project")+len("Ancilla Project")]
errors=[[r[0],r[1],r[2][:r[2].find(" ")],r[2][r[2].find(" ")+1:]] for r in[(len(e[:len(e)-len(e.lstrip())]),f"{'0'*(3-len(str(i)))}{i}",e[len(e)-len(e.lstrip()):],) for i,e in enumerate(open(r("cache/errors.log")).read().split("\n"))]]
def error(q,obj=False):
a=[e for e in errors if (f"{'0'*(3-len(str(q)))}{q}" if isinstance(q,int) else q)==e[1 if isinstance(q,int) else 2]];return ((a[0] if a else None) if not obj else ({**globals(),**vars(builtins)}[a[0][2]] if a else None))
for i,e in enumerate(errors):
errors[i]=([(*e,(*errors[int(e[1])-x-1],int(e[1])-x-1)) for x in range(0,int(e[1])) if errors[int(e[1])-x-1][0]<e[0]] if e[0]!=0 else [(*e,(*error("BaseException"),)),] if e[2]!="BaseException" else [(*e,),])[0];e=errors[i]
If any more information or clarity is needed I will try my best to give them. And yeah, i know that the amount of PEP violation (whichever one is for python 3.8.6) is so high that it'd collapse under its own gravity and become a blackhole- so some help on that would be appreciated