bionic icon indicating copy to clipboard operation
bionic copied to clipboard

Confusing error message when non-iterable input used with `outputs`

Open jqmp opened this issue 4 years ago • 0 comments
trafficstars

Sometimes users pass a single argument to @bn.outputs, expecting it to work like @bn.output:

builder = bn.FlowBuilder('test')

@builder
@bn.outputs('value')
def _():
    return 7

flow = builder.build()

flow.get('value')

This fails because @outputs expects the decorated function to return a sequence with one value. The correct thing would be to either return the tuple 7,, or use @bn.output instead of @bn.outputs. However, the error message could be more helpful:

EntityValueError: Value received for '<value>,' is not valid for TupleProtocol due to <class 'AssertionError'>: 'int' object is not iterable

The message is correct, but it would be better to state what was expected (a sequence of length 1). We could even go farther and say something like "did you mean to use @output instead of @outputs?". (Also, we should probably replace the <class 'AssertionError'> with just AssertionError.

jqmp avatar Feb 06 '21 15:02 jqmp