Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
49.57k stars 1.73k forks source link

[REQUEST] Shortening error messages of certain modules similarly to frame suppression in tracebacks #3271

Open ibro45 opened 9 months ago

ibro45 commented 9 months ago

How would you improve Rich?

Allow automatic shortening of error messages. Could be implemented similarly to frame suppression. A shortened message would keep only, for example, 3 lines, and the number of lines could be controlled similarly to max_frames in Traceback

What problem does it solve for you?

Chained exceptions can get quite long in frameworks that build on top of several other codebases. The error messages in some of the exceptions in the chain can be almost certainly always useless. Shortening them would make debugging way simpler.

In my framework, I would by default have certain modules' error messages shortened/supressed automatically, unless the debug mode is activated.

For example, the RuntimeError here:

image

Would become this if max_error_lines=3 (or whatever the name would be):

RuntimeError: Failed to instantiate component 'lighter.utils.model.adjust_prefix_and_load_state_dict' with kwargs: {'ckpt_to_model_prefix': 
{'_orig_mod.': ''}, 'ckpt_path': '/mnt/ssd1/rogueone/ibro/CT_FM/ct_fm_nsclc/checkpoints_8_Jan_2024/random_init_100/epoch=152-step=6579.ckpt', 
'model': SegResNetDS(
...

Alternative Please let me know if there is already a way to achieve this. Also, if this is something that you would indeed like to have, feel free to briefly instruct me in how it could be achieved and I would be happy to try to make a pull request.

github-actions[bot] commented 9 months ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

ibro45 commented 9 months ago

or, alternatively, add an option to just shorten the error messages of the already suppressed modules. That won't be as complex and will probably be just enough amount of control -- in my case, that would actually be perfect.