Scons swallowing exception stack trace for jinja2.exceptions.TemplateNotFound

Samir Mahaboob Khan Kagadkar via Scons-users <[email protected]> Tue, 14 May 2024 04:16:14 +0000
Newsgroups gmane.comp.programming.tools.scons.user
Message-ID <DS0PR02MB9353FDF4D98A175CC86DE1ABE2E32@DS0PR02MB9353.namprd02.prod.outlook.com>
Hi SCons Team,

I use the Jinja2 templating language (https://jinja.palletsprojects.com/en/3.1.x/) to generate scripts from within SCons.

Jinja2 raises the TemplateNotFound (jinja2.exceptions.TemplateNotFound) exception when, say, a file included in the template cannot be found.

Unfortunately scons does not show the exception stack trace when this is raised as part of a builder.

Here is a simple SConstruct that demonstrates this:

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)

Here is the output not showing any stack trace:
$ scons -f <path_to_sconstruct_dir>/SConstruct dummy/TEST.COMPLETE
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
small_builder(["dummy/TEST.COMPLETE"], [])
scons: done building targets.

The TemplateNotFound can be raised in a simple standalone python3 script invocation:
import jinja2
raise jinja2.exceptions.TemplateNotFound("You should see this message")

with the below output
$ python3 test1.py
Traceback (most recent call last):
  File "test1.py", line 2, in <module>
    raise jinja2.exceptions.TemplateNotFound("You should see this message")
jinja2.exceptions.TemplateNotFound: You should see this message

Other exceptions work in SCons builders, of course. For example:
import jinja2
 def small_builder(target, source, env):
     #raise jinja2.exceptions.TemplateNotFound("You should see this message")
     raise ValueError("You should see this message")
 env=Environment()
env.Command(['dummy/TEST.COMPLETE'], [], small_builder, chdir=0)


with the following output:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
small_builder(["dummy/TEST.COMPLETE"], [])
scons: *** [dummy/TEST.COMPLETE] ValueError : You should see this message
Traceback (most recent call last):
  File “<….>/SCons/Action.py", line 1441, in execute
    result = self.execfunction(target=target, source=rsources, env=env)
  File "<….> /SConstruct", line 5, in small_builder
    raise ValueError("You should see this message")
ValueError: You should see this message
scons: building terminated because of errors.

I am running all of this on the latest scons:
scons --version
SCons by Steven Knight et al.:
        SCons: v4.7.0.265be6883fadbb5a545612265acc919595158366, Sun, 17 Mar 2024 17:33:54 -0700, by bdbaddog on M1Dog2021

Could you please take a look?

Thanks
Samir

_______________________________________________
Scons-users mailing list
[email protected]
https://pairlist4.pair.net/mailman/listinfo/scons-users