Skip to content

SCons may convert another exception to BuildError incorrectly #4530

Closed

Description

@mwichmann

An internal SCons routine, SCons.Errors.convert_to_BuildError, attempts to synthesize a BuildError exception from whatever exception may have been raised when the Taskmaster executes an action. This can go wrong in certain circumstances. The docstring for the BuildError class contains these comments:

errstr: a description of the error message
status: the return code of the action that caused the build error. Must be set to a non-zero value even if the build error is not due to an action returning a non-zero returned code.

In the case reported in the linked thread, the Jinja templating engine (used in-process) raised a jinja2.exceptions.TemplateNotFound exception, which is initialized in a kind of odd way (separate topic), where the three important exception fields filename, strerror and errno are all set to None. The conversion routine then tries this (status contains the captured exception at this point):

    filename = getattr(status, 'filename', None) 
    strerror = getattr(status, 'strerror', str(status)) 
    errno = getattr(status, 'errno', 2) 

before stuffing those values into the BuildError instance. As written, strerror and errno will remain None if they were None in the original exception, which is not the intent of the routine, as described in the docstring (the getattr defaults only apply if the attributes are not present). The effect is that the exception appears to be "swallowed". SCons should be more tolerant of this, and get the defaults in if the fields were None.

Simple repro:

import jinja2

def small_builder(target, source, env):
    raise jinja2.exceptions.TemplateNotFound("You should see this message")

env=Environment()
env.Command(['dummy/TEST.COMPLETE'], [], small_builder, chdir=0)

Activity

  1. added a commit that references this issue on May 16, 2024
    3d47e1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions