You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before the conversion to Pydantic, problems in the config files would raise MalformedMapping with an (at least somewhat) informative message.
Now we get a pydantic error that's much harder to interpret. We should try to catch it it the right place and augment it with user-informative details.
E.g., set abbreviations_path: 1.0 in any mapping config and running g2p udpate yields this:
$ g2p update
INFO - Loading alignments from c:\users\joanise\sandboxes\g2p\g2p\mappings\langs\eng\cmudict.ipa.aligned.txt
Traceback (most recent call last):
File "C:\Users\joanise\Miniconda3\envs\ras-py310\Scripts\g2p-script.py", line 33, in <module>
sys.exit(load_entry_point('g2p', 'console_scripts', 'g2p')())
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 1053, in main
rv = self.invoke(ctx)
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "c:\users\joanise\sandboxes\g2p\g2p\cli.py", line 662, in update
cache_langs(dir_path=in_dir, langs_path=langs_path, network_path=network_path)
File "c:\users\joanise\sandboxes\g2p\g2p\mappings\langs\utils.py", line 163, in cache_langs
mapping_config = MappingConfig.load_mapping_config_from_path(path)
File "c:\users\joanise\sandboxes\g2p\g2p\mappings\__init__.py", line 434, in load_mapping_config_from_path
return MappingConfig(**loaded_config)
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\pydantic\main.py", line 171, in __init__
self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for MappingConfig
mappings.0.abbreviations_path
Input is not a valid path [type=path_type, input_value=1.0, input_type=float]
Or, a more realistic case where the file just doesn't exist:
$ g2p update
INFO - Loading alignments from c:\users\joanise\sandboxes\g2p\g2p\mappings\langs\eng\cmudict.ipa.aligned.txt
Traceback (most recent call last):
File "C:\Users\joanise\Miniconda3\envs\ras-py310\Scripts\g2p-script.py", line 33, in <module>
sys.exit(load_entry_point('g2p', 'console_scripts', 'g2p')())
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 1053, in main
rv = self.invoke(ctx)
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\click\core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "c:\users\joanise\sandboxes\g2p\g2p\cli.py", line 662, in update
cache_langs(dir_path=in_dir, langs_path=langs_path, network_path=network_path)
File "c:\users\joanise\sandboxes\g2p\g2p\mappings\langs\utils.py", line 163, in cache_langs
mapping_config = MappingConfig.load_mapping_config_from_path(path)
File "c:\users\joanise\sandboxes\g2p\g2p\mappings\__init__.py", line 434, in load_mapping_config_from_path
return MappingConfig(**loaded_config)
File "C:\Users\joanise\Miniconda3\envs\ras-py310\lib\site-packages\pydantic\main.py", line 171, in __init__
self.__pydantic_validator__.validate_python(data, self_instance=self)
File "c:\users\joanise\sandboxes\g2p\g2p\mappings\__init__.py", line 51, in model_post_init
self.abbreviations = load_abbreviations_from_file(
File "c:\users\joanise\sandboxes\g2p\g2p\mappings\utils.py", line 426, in load_abbreviations_from_file
with open(path, encoding="utf8") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'c:\\users\\joanise\\sandboxes\\g2p\\g2p\\mappings\\langs\\fra\\file_does_not_exist.csv'
The stack trace is not really helpful, and there is no indicate as to which config file has the problem, which is what the user needs to know.
The text was updated successfully, but these errors were encountered:
Before the conversion to Pydantic, problems in the config files would raise
MalformedMapping
with an (at least somewhat) informative message.Now we get a pydantic error that's much harder to interpret. We should try to catch it it the right place and augment it with user-informative details.
E.g., set
abbreviations_path: 1.0
in any mapping config and runningg2p udpate
yields this:Or, a more realistic case where the file just doesn't exist:
The stack trace is not really helpful, and there is no indicate as to which config file has the problem, which is what the user needs to know.
The text was updated successfully, but these errors were encountered: