IngoMeyer441 / simple-term-menu

A Python package which creates simple interactive menus on the command line.
MIT License
492 stars 43 forks source link

unexpected AssertionError #65

Closed PyzMenPL closed 1 year ago

PyzMenPL commented 2 years ago

Hi, I am currently making a learning program. I was in the process of modifying my module responsible for saving files, when I finished this I wanted to check if the prevention of creating files without a name was working as expected, so using my program I tried to create a '.json' file. The program crashed and threw up some weird error that starts in a completely different part of my code and ends up in the simple-term-menu library code. I run the code again to see if it works at least to prevent the creation of 2 of the same file and it turns out I can't do anything, because my main menu isn't working. The program throws the same error as before, only now on startup. This is what the error looks like:

Traceback (most recent call last): File "main.py", line 284, in menu.showMenu() File "main.py", line 71, in showMenu menuMain = TerminalMenu(fullList, cursor_index=cursorIndex) File "/.local/lib/python3.10/site-packages/simple_term_menu.py", line 667, in init ) = extract_shortcuts_menu_entries_and_preview_arguments(menu_entries) File "/.local/lib/python3.10/site-packages/simple_term_menu.py", line 604, in extract_shortcuts_menu_entries_and_preview_arguments assert match_obj is not None AssertionError

What might be the problem here?

IngoMeyer441 commented 2 years ago

Hey and thanks for using my library. Menu entries can contain some special characters to encode additional information into a menu entry and the routine you are referencing extracts these meta information. Probably your menu entries contain at least one of these special characters but not in a format which simple-term-menu would expect. The possibilities:

Does this already help? Do your menu entries contain brackets or bars?

PyzMenPL commented 1 year ago

I worked it out šŸ˜… When I tried to test whether the user could create an empty file, I didn't implement anything to prevent them from doing so, just a simple print("You can't create file without name!"), I was sure that you couldn't just create a file with . at the beginning of its name. And contrary to my assumption, the file was created .json. Every time I get a list of files, the program removes the .json from them and adds [ ] before and after the folder name. I didn't have skip_empty_entries=True and what happened was that I got the .json file replaced with '' and that turned out to be the source of my problem. The situation is funny because files that start with . are hidden and I had no idea this file was even created šŸ˜€

Sorry for bothering you and thanks for your reply šŸ˜€