[Refactor] Improve error message when improperly configuring scenario
๐ Description
I mistakenly wrote the following code:
import taipy as tp
from taipy import Config, Orchestrator
def square(number: int) -> int:
return number**2
number_cfg = Config.configure_data_node(id="number")
squared_number_cfg = Config.configure_data_node(id="squared_number")
square_task_cfg = Config.configure_task(id="square_task", function=square, input=number_cfg, output=squared_number_cfg)
scenario_cfg = Config.configure_scenario(id="square_scenario", tasks_configs=[square_task_cfg])
Orchestrator().run()
scenario = tp.create_scenario(scenario_cfg)
and got the following error:
Traceback (most recent call last):
File "/home/main.py", line 15, in <module>
scenario = tp.create_scenario(scenario_cfg)
File "/home/.venv-git-2025-05-22/lib/python3.10/site-packages/taipy/core/taipy.py", line 915, in create_scenario
return _ScenarioManagerFactory._build_manager()._create(config, creation_date, name)
File "/home/.venv-git-2025-05-22/lib/python3.10/site-packages/taipy/core/scenario/_scenario_manager.py", line 194, in _create
cls._repository._save(scenario)
File "/home/.venv-git-2025-05-22/lib/python3.10/site-packages/taipy/core/_repository/_filesystem_repository.py", line 65, in _save
json.dumps(model.to_dict(), ensure_ascii=False, indent=0, cls=_Encoder, check_circular=False),
File "/home/.venv-git-2025-05-22/lib/python3.10/site-packages/taipy/core/_repository/_base_taipy_model.py", line 26, in to_dict
model_dict = {**dataclasses.asdict(self)} # type: ignore[call-overload]
File "/home/.pyenv/versions/3.10.10/lib/python3.10/dataclasses.py", line 1238, in asdict
return _asdict_inner(obj, dict_factory)
File "/home/.pyenv/versions/3.10.10/lib/python3.10/dataclasses.py", line 1245, in _asdict_inner
value = _asdict_inner(getattr(obj, f.name), dict_factory)
File "/home/.pyenv/versions/3.10.10/lib/python3.10/dataclasses.py", line 1275, in _asdict_inner
return type(obj)((_asdict_inner(k, dict_factory),
File "/home/.pyenv/versions/3.10.10/lib/python3.10/dataclasses.py", line 1276, in <genexpr>
_asdict_inner(v, dict_factory))
File "/home/.pyenv/versions/3.10.10/lib/python3.10/dataclasses.py", line 1273, in _asdict_inner
return type(obj)(_asdict_inner(v, dict_factory) for v in obj)
File "/home/.pyenv/versions/3.10.10/lib/python3.10/dataclasses.py", line 1273, in <genexpr>
return type(obj)(_asdict_inner(v, dict_factory) for v in obj)
File "/home/.pyenv/versions/3.10.10/lib/python3.10/dataclasses.py", line 1279, in _asdict_inner
return copy.deepcopy(obj)
File "/home/.pyenv/versions/3.10.10/lib/python3.10/copy.py", line 161, in deepcopy
rv = reductor(4)
TypeError: 'NoneType' object is not callable
My mistake was that I did tasks_configs instead of task_configs.
Error message could be improved when the core configuration is misconfigured.
๐ Code of Conduct
- [x] I have checked the existing issues to avoid duplicates.
- [ ] I am willing to work on this issue (optional)
โ Acceptance Criteria
- [ ] The refactored code maintains existing functionality without breaking changes.
- [ ] Any new code is covered by unit tests.
- [ ] Code coverage remains at least 90%.
- [ ] Performance improvements are documented, if applicable.
We cannot prevent the user from passing an incorrect parameter name, as they can pass any additional parameter.
However, we can investigate why the message is not understandable.
Some thoughts
Consideration 1: Is there a use case where only the id property (i.e. Config.configure_scenario(id="scenario") is provided?
Even if there is a use case, perhaps Config.configure_scenario could print a warning when neither task_configs or additional_data_node_configs (which probably cover 90-100% of use cases) are specified?
Consideration 2: Improve error messages when passing invalid kwarg value:
-
Config.configure_scenario(id="scenario", hello="world"): Valid action, no error. -
..., hello=square_task_cfg): Invalid action, error in main post -
..., hello=square): Invalid action, error: "TypeError: Object of type function is not JSON serializable"
IMO, if the erroneous line doesn't appear in the stack trace (which it doesn't), then it would be better to catch and print a better error.
Pls assign this task to me, lemme take a look into this
@DeeshantGupta You are assigned. Thank you for your help.
Thanks for assigning it, give me some time ๐
This issue has been labelled as "๐ฅถWaiting for contributor" because it has been inactive for more than 14 days. If you would like to continue working on this issue, please add another comment or create a PR that links to this issue. If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. Otherwise, you will be unassigned in 14 days. For more information please refer to the contributing guidelines.
This issue has been unassigned automatically because it has been marked as "๐ฅถWaiting for contributor" for more than 14 days with no activity.