@contextmanager<EOL>def user_code_context_manager(user_fn, error_cls, msg):
check.callable_param(user_fn, '<STR_LIT>')<EOL>check.subclass_param(error_cls, '<STR_LIT>', DagsterUserCodeExecutionError)<EOL>with user_code_error_boundary(error_cls, msg):<EOL><INDENT>thing_or_gen = user_fn()<EOL>gen = _ensure_gen(thing_or_gen)<EOL>try:<EOL><INDENT>thing = next(gen)<EOL><DEDENT>except StopIteration:<EOL><INDENT>check.failed('<STR_LIT>')<EOL><DEDENT>yield thing<EOL>stopped = False<EOL>try:<EOL><INDENT>next(gen)<EOL><DEDENT>except StopIteration:<EOL><INDENT>stopped = True<EOL><DEDENT>check.invariant(stopped, '<STR_LIT>')<EOL><DEDENT>
Wraps the output of a user provided function that may yield or return a value and
    returns a generator that asserts it only yields a single value.