Voxel-Fox-Ltd / VoxelBotUtils

An extension of the Discord.py library to improve the bot development process.
https://voxelbotutils.readthedocs.io/en/latest/
GNU General Public License v2.0
34 stars 12 forks source link

Error catching for creating config when files already exist #64

Closed irismessage closed 3 years ago

irismessage commented 3 years ago

e.g.

py -m voxelbotutils create-config bot
Traceback (most recent call last):
  File "C:\Users\joelm\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\joelm\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\joelm\Documents\_Programming\_python\Apple.Py\.venv\lib\site-packages\voxelbotutils\__main__.py", line 201, in <module>
    main()
  File "C:\Users\joelm\Documents\_Programming\_python\Apple.Py\.venv\lib\site-packages\voxelbotutils\__main__.py", line 162, in main
    create_file("config", "config.toml", content=config.config_file.lstrip(), throw_error=True)
  File "C:\Users\joelm\Documents\_Programming\_python\Apple.Py\.venv\lib\site-packages\voxelbotutils\__main__.py", line 19, in create_file
    raise e
  File "C:\Users\joelm\Documents\_Programming\_python\Apple.Py\.venv\lib\site-packages\voxelbotutils\__main__.py", line 15, in create_file
    with open(f"./{os.sep.join(path)}", "x") as a:
FileExistsError: [Errno 17] File exists: './config\\config.toml'
4Kaylum commented 3 years ago

The config file doesn't get caught deliberately because there may be things in there that you've altered. Other files are silently discarded when they duplicate. See the throw_error=True arg. This is a deliberate design decision.

irismessage commented 3 years ago

I see that. I would personally prefer it however if, when the config file exists, it's left alone, and any files that don't exist are created. But I guess I can make run_bot.py manually.

4Kaylum commented 3 years ago

How about a catch with a printout - "file X was left unchanged due to already existing" instead of silent?

irismessage commented 3 years ago

Yup sounds good to me