xnuinside / omymodels

O!My Models (omymodels) is a library to generate Pydantic, Dataclasses, GinoORM Models, SqlAlchemy ORM, SqlAlchemy Core Table, Models from SQL DDL. And convert one models to another.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

create_models() exits entire program if no tables are found

dargueta opened this issue · comments

Describe the bug

If create_models() doesn't find tables in the DDL string it's given, it exits the program.

To Reproduce

In an interpreter (IDLE, IPython, etc.) run create_models() with a string containing only whitespace. The interpreter exits.

Expected behavior

If this function is to be used in a library, ideally an exception would be thrown with information about the error. The issue is here; I'd greatly appreciate it if you could throw, say, a ValueError or something instead of exiting.

Personally, when I'm making a library, I like creating my own error hierarchy (e.g. here) so the source of the exception is very clear to the caller, and they can selectively catch certain errors. For example, here I would create two exceptions:

# omymodels/errors.py

class Error(Exception):
    """Base class for most if not all errors thrown by this library""

class NoTablesFoundError(Error):
    """No tables were found in the DDL string."""

Then instead of sys.exit() I would throw NoTablesFoundError. This design allows me to add new exceptions as I see fit, and standardize error messages (example here).

These are my personal design habits, don't let me dictate yours!

Additional context

Python: 3.8.2
Version: 0.8.3

@dargueta interesting, I will try reproduce it on the evening and fix it. About errors - I'm doing it similar ways usually. In this library I just had not time to came yet to handle exceptions proper way :)

Thanks! Sorry I'm being such a pain with all these tickets. 😅

@dargueta no :) I’m glad that package can be useful somehow, if will be any suggestions or issues feel free to open new tickets!