baobabsoluciones/mango

Implement traceback formatting with filtering

Open

#150 opened on Nov 7, 2024

 (0 comments) (0 reactions) (0 assignees)Python (2 forks)auto 404
good first issue

Repository metrics

Stars
 (3 stars)
PR merge metrics
 (PR metrics pending)

Description

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)
    

Contributor guide