baobabsoluciones/mango

Implement traceback formatting with filtering

Aperta

#150 aperta il 7 nov 2024

 (0 commenti) (0 reazioni) (0 assegnatari)Python (2 fork)auto 404
good first issue

Metriche repository

Star
 (3 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

In other projects I have been using functions like this one (maybe there are libraries that do something similar, airflow does):

def parse_traceback(exc_type, exc_value, tb):
    tb_parsed = traceback.format_tb(tb)
    cleaned_traceback = []

    for line in tb_parsed:
        # Find "super_secret" and remove everything before it, replacing with "***"
        cleaned_line = re.sub(
            r".*super_secret.*", r' "***', line
        )
        # Remove \n
        cleaned_line = cleaned_line.replace("\n", "")
        # Clean \t
        cleaned_line = cleaned_line.replace("\t", " ")
        # Remove more than 1 space
        cleaned_line = re.sub(r" {2,}", " ", cleaned_line)
        # If line empty skip it
        if cleaned_line:
            cleaned_traceback.append(cleaned_line)

    return " ".join(cleaned_traceback)
    

Guida contributor