Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error messaging if toml file is not well formatted #322

Closed
chStaiger opened this issue Sep 5, 2024 · 0 comments · Fixed by #327
Closed

Error messaging if toml file is not well formatted #322

chStaiger opened this issue Sep 5, 2024 · 0 comments · Fixed by #327
Milestone

Comments

@chStaiger
Copy link

I am creating synthetic data with a toml file. When the toml file is not well formatted metsyn throws this error message:

staig001@busoni autumn-fair % metasyn create-meta  --config event_config.toml
Traceback (most recent call last):
  File "/Users/staig001/.local/bin/metasyn", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/__main__.py", line 80, in main
    create_metadata()
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/__main__.py", line 127, in create_metadata
    meta_frame = MetaFrame.from_config(meta_config)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/metaframe.py", line 169, in from_config
    return cls.fit_dataframe(None, meta_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/metaframe.py", line 140, in fit_dataframe
    var = MetaVar(
          ^^^^^^^^
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/var.py", line 72, in __init__
    if self.prop_missing < -1e-8 or self.prop_missing > 1 + 1e-8:
       ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'float'
staig001@busoni autumn-fair % metasyn create-meta  --config event_config.toml
Traceback (most recent call last):
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/config.py", line 102, in from_toml
    config_dict = tomllib.load(handle)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tomllib/_parser.py", line 66, in load
    return loads(s, parse_float=parse_float)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tomllib/_parser.py", line 127, in loads
    raise suffixed_err(
tomllib.TOMLDecodeError: Expected newline or end of document after a statement (at line 44, column 8)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/staig001/.local/bin/metasyn", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/__main__.py", line 80, in main
    create_metadata()
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/__main__.py", line 120, in create_metadata
    meta_config = MetaConfig.from_toml(args.config)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/staig001/.local/pipx/venvs/metasyn/lib/python3.12/site-packages/metasyn/config.py", line 109, in from_toml
    raise ValueError(f"It appears '{Path(config_fp).name}' is a"
ValueError: It appears 'event_config.toml' is a '.toml' file. To load a MetaConfig, provide it as a .toml file.

Is it possible to distinguish whether the file was not a toml file or whether it is an incorrectly formatted toml file and adjust the feedback in the error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants