Exemplo n.º 1
0
def render_error(project: 'projects.Project',
                 error: Exception,
                 stack: typing.List[dict] = None) -> dict:
    """
    Renders an Exception to an error response that includes rendered text and
    html error messages for display.

    :param project:
        Currently open project.
    :param error:
        The SyntaxError to be rendered to html and text for display.
    :param stack:
        Optionally specify a parsed stack. If this value is None the standard
        Cauldron stack frames will be rendered.
    :return:
        A dictionary containing the error response with rendered display
        messages for both text and html output.
    """

    data = dict(type=error.__class__.__name__,
                message='{}'.format(error),
                stack=(stack if stack is not None else
                       render_stack.get_formatted_stack_frame(project)))

    return dict(success=False,
                error=error,
                message=templating.render_template('user-code-error.txt',
                                                   **data),
                html_message=templating.render_template(
                    'user-code-error.html', **data))
Exemplo n.º 2
0
def render_stop_display(step: 'projects.ProjectStep', message: str):
    """Renders a stop action to the Cauldron display."""
    stack = render_stack.get_formatted_stack_frame(
        project=step.project,
        error_stack=False
    )

    try:
        names = [frame['filename'] for frame in stack]
        index = names.index(os.path.realpath(__file__))
        frame = stack[index - 1]
    except Exception:
        frame = {}

    stop_message = (
        '{}'.format(message)
        if message else
        'This step was explicitly stopped prior to its completion'
    )

    dom = templating.render_template(
        'step-stop.html',
        message=stop_message,
        frame=frame
    )
    step.report.append_body(dom)
Exemplo n.º 3
0
def render_stop_display(step: 'projects.ProjectStep', message: str):
    """Renders a stop action to the Cauldron display."""
    stack = render_stack.get_formatted_stack_frame(project=step.project,
                                                   error_stack=False)

    try:
        names = [frame['filename'] for frame in stack]
        index = names.index(os.path.realpath(__file__))
        frame = stack[index - 1]
    except Exception:
        frame = {}

    stop_message = ('{}'.format(message) if message else
                    'This step was explicitly stopped prior to its completion')

    dom = templating.render_template('step-stop.html',
                                     message=stop_message,
                                     frame=frame)
    step.report.append_body(dom)
Exemplo n.º 4
0
    def stop(self, message: str = None, silent: bool = False):
        """
        Stops the execution of the current step immediately without raising
        an error. Use this to abort the step running process if you want
        to return early.

        :param message:
            A custom display message to include in the display for the stop
            action. This message is ignored if silent is set to True.
        :param silent:
            When True nothing will be shown in the notebook display when the
            step is stopped. When False, the notebook display will include
            information relating to the stopped action.
        """

        step = self._step

        if not step:
            return

        if not silent:
            stack = render_stack.get_formatted_stack_frame(
                project=step.project, error_stack=False)

            try:
                names = [frame['filename'] for frame in stack]
                index = names.index(os.path.realpath(__file__))
                frame = stack[index - 1]
            except Exception:
                frame = {}

            stop_message = (
                '{}'.format(message) if message else
                'This step was explicitly stopped prior to its completion')

            dom = templating.render_template('step-stop.html',
                                             message=stop_message,
                                             frame=frame)
            step.report.append_body(dom)

        raise UserAbortError()
Exemplo n.º 5
0
def render_error(
        project: 'projects.Project',
        error: Exception,
        stack: typing.List[dict] = None
) -> dict:
    """
    Renders an Exception to an error response that includes rendered text and
    html error messages for display.

    :param project:
        Currently open project.
    :param error:
        The SyntaxError to be rendered to html and text for display.
    :param stack:
        Optionally specify a parsed stack. If this value is None the standard
        Cauldron stack frames will be rendered.
    :return:
        A dictionary containing the error response with rendered display
        messages for both text and html output.
    """

    data = dict(
        type=error.__class__.__name__,
        message='{}'.format(error),
        stack=(
            stack
            if stack is not None else
            render_stack.get_formatted_stack_frame(project)
        )
    )

    return dict(
        success=False,
        error=error,
        message=templating.render_template('user-code-error.txt', **data),
        html_message=templating.render_template('user-code-error.html', **data)
    )