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 messages improvement #921

Open
ljyanesm opened this issue Jan 11, 2024 · 0 comments
Open

Error messages improvement #921

ljyanesm opened this issue Jan 11, 2024 · 0 comments

Comments

@ljyanesm
Copy link

Currently when one is creating a Workflow with steps that may be defined elsewhere, for example having a separate python function that defines the Steps and invoking it from a Workflow users may try to instantiate the Steps outside the context of the Workflow leading to a non-intuitive error message.

For example:

@script()
def echo(message: str):
    print(message)

def my_steps_def():
    with Steps(name="steps") as my_steps:
        echo(arguments={"message": "Hello world!"})
    return my_steps


my_steps = my_steps_def()
with Workflow(
    generate_name="hello-world-",
    entrypoint="steps",
) as wf:
    my_steps

if __name__ == "__main__":
    # dump as yaml for inspection
    with pathlib.Path(__file__).with_suffix(".yaml").open("w") as fh:
        wf.to_yaml(fh)

Leads to the following stacktrace:

Traceback (most recent call last):
  File "/testing/hera-examples/reusable-steps-error-message.py", line 18, in <module>
    my_steps = my_steps_def()
               ^^^^^^^^^^^^^^
  File "/testing/hera-examples/reusable-steps-error-message.py", line 14, in my_steps_def
    echo(arguments={"message": "Hello world!"})
  File "/testing/.venv/lib/python3.11/site-packages/hera/workflows/script.py", line 599, in task_wrapper
    return s.__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/testing/.venv/lib/python3.11/site-packages/hera/workflows/_mixins.py", line 667, in __call__
    return Step(*args, template=self, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 349, in pydantic.main.BaseModel.__init__
  File "/testing/.venv/lib/python3.11/site-packages/hera/shared/_global_config.py", line 150, in _init_private_attributes
    self.__hera_init__()
  File "/testing/.venv/lib/python3.11/site-packages/hera/workflows/_context.py", line 28, in __hera_init__
    _context.add_sub_node(self)
  File "/testing/.venv/lib/python3.11/site-packages/hera/workflows/_context.py", line 93, in add_sub_node
    for t in pieces[0].templates:  # type: ignore
             ^^^^^^^^^^^^^^^^^^^
AttributeError: 'Steps' object has no attribute 'templates'

The error message above could be improved by suggesting the user that the object that is being instantiated should be within a Workflow context.

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

No branches or pull requests

1 participant