Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Error messages are cryptic #50

Open
dylanwal opened this issue Oct 31, 2022 · 2 comments
Open

Error messages are cryptic #50

dylanwal opened this issue Oct 31, 2022 · 2 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@dylanwal
Copy link
Contributor

When saving with an invalid material property 'key'; it throws a unhelpful TypeError

  File "<@beartype(cript.data_model.subobjects.property.Property.__init__) at 0x2a7e1270a60>", line 435, in __init__
TypeError: __init__() missing 1 required positional argument: 'key'

@dylanwal
Copy link
Contributor Author

dylanwal commented Nov 1, 2022

Code that causes the error:


import cript as c


def make_material(project: c.Project):
    water = c.Material(
        project=project,
        group=project.group,
        name="water",
        identifiers=[
            c.Identifier("preferred_name", "water"),
            c.Identifier("names", ["h2o", "dihydrogen oxide"]),
            c.Identifier("cas", "7732-18-5"),
            c.Identifier("smiles", "O"),
            c.Identifier("chem_formula", "H2O"),
            c.Identifier("pubchem_cid", 962),
            c.Identifier("inchi_key", "XLYOFNOQVPJJNP-UHFFFAOYSA-N"),
        ],
        properties=[
            c.Property(key="phase", value="liquid"),
            c.Property(key="color", value="colorless"),
            c.Property(
                key="molar_mass", value=18.015, unit="g/mol", method="prescribed"
            ),
            c.Property(
                key="density",
                value=1.0,
                unit="g/ml",
                conditions=[c.Condition(key="temperature", value=4, unit="degC")],
            ),
            c.Property(
                key="+temp_boiling",
                value=100,
                unit="degC",
                conditions=[c.Condition(key="pressure", value=1, unit="atm")],
            ),
            c.Property(
                key="temp_melt",
                value=0,
                unit="degC",
                conditions=[c.Condition(key="pressure", value=1, unit="bar")],
            ),
        ],
    )
    water.save()  # will raise TypeError


def main():
    
    # API login
    import pathlib
    host = "criptapp.org"
    with open(str(pathlib.Path(__file__).parent.parent) + "\\api_key.txt", "r") as f:
        token = f.read()
    api = c.API(host, token)

    # make material 
    project = c.Project.get(name="test_sdk_project")
    make_material(project)


if __name__ == "__main__":
    main()

*The issue is the "custom attribute" for Property '+temp_boiling'.

@dylanwal
Copy link
Contributor Author

dylanwal commented Nov 1, 2022

Possible solutions:

  • the error happens in 'base.py: line 134' so some complex error handling could be done here.
  • or refactor back to API.save() so errors can be handled better.

@dylanwal dylanwal added bug Something isn't working enhancement New feature or request labels Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant