unpackAI / Ai101

A program for non-coders to get started with machine learning development. The course contains flexible and powerful ML pipelines for computer vision, tabular, recommender systems and NLP problems
MIT License
7 stars 8 forks source link

Better/prettier error message handler, ideally with debugging suggestions #6

Open faizer1989 opened 2 years ago

faizer1989 commented 2 years ago

For week 4. "NLP week" we already have a nice error message display thanks to Jeff.

The main issue: students make lots of unintentional errors and don't have an understanding of how to approach the debugging of some simple errors.

The error messaging thus should be beginner-friendly and encouraging to debug.

Some error handling python packages:

jamescavanagh commented 2 years ago

@jfthuong Hi Jeff, I am interested in how you impliment this error handling. is there documentation on it?

jfthuong commented 2 years ago

Nice idea.

I believe it's @raynardj who developed the system that caught the exceptions and proposed some solutions based on some simple database.

The listed modules are interesting.

raynardj commented 2 years ago

Hmmm, it changes how ipython kernel run the cell's code, add a layer of exception handling

https://github.com/unpackAI/unpackai/blob/d8aef3a3fb45887653df13d0ea742e78e876b638/unpackai/bug.py#L113-L119

You can easily design more friendly messages by updating BUGBOOK

It's a dictionary, the key is the name of the error, the value is the message: a string of html source code

from unpackai.bug import BUGBOOK

BUGBOOK["SyntaxError"] ="""
<h5>There is a <strong>grammatical</strong> error in your python code</h5>
<p>Please check the following</p>
<p>Every '(' or '[' or '{' or '"' or ' was closed with properly</p>
<p>':' should be followed by a new line with 1 extra <strong>indent</strong> (4 spaces)</p>
<p>or other grammatical errors, please check traceback below for clue, usually <strong>near ^ mark</strong></p>
"""

For more advanced error catching, you can define a error filter function

A function will return True if it's the error you want to replace the message.

The function can be used as the key for BUGBOOK, without "

# functions that we can use as key of the fule
def module_not_found_error_filter(etype, evalue, tb):
    if etype.__name__ == "ModuleNotFoundError":
        libname = str(evalue).replace("No module named ", "")[1:-1]
        if libname in ["fastai", "unpackai", "transformers","test_filter"]:
            return True
    return False
raynardj commented 2 years ago

Of course the original design is to gather errors along with the student's code and send to our own backend so we can analyze their activity and most encountered pitfalls, but that's a long lead to follow

@jamescavanagh