Skip to content

Commit 21f4232

Browse files
committed
Make exceptions less verbose by default
1 parent 3af923b commit 21f4232

File tree

3 files changed

+220
-222
lines changed

3 files changed

+220
-222
lines changed

pytensor/compile/function/types.py

+19-25
Original file line numberDiff line numberDiff line change
@@ -949,32 +949,26 @@ def __call__(self, *args, output_subset=None, **kwargs):
949949

950950
except Exception as e:
951951
i = input_storage.index(arg_container)
952-
function_name = "pytensor function"
953-
argument_name = "argument"
954-
if self.name:
955-
function_name += ' with name "' + self.name + '"'
956-
if hasattr(arg, "name") and arg.name:
957-
argument_name += ' with name "' + arg.name + '"'
958-
where = get_variable_trace_string(self.maker.inputs[i].variable)
959-
if len(e.args) == 1:
960-
e.args = (
961-
"Bad input "
962-
+ argument_name
963-
+ " to "
964-
+ function_name
965-
+ f" at index {int(i)} (0-based). {where}"
966-
+ e.args[0],
952+
function_name = (
953+
"pytensor function"
954+
if self.name
955+
else f"pytensor function '{self.name}'"
956+
)
957+
argument_name = (
958+
f"argument {arg.name}"
959+
if hasattr(arg, "name")
960+
else "argument"
961+
)
962+
where = (
963+
""
964+
if config.exception_verbosity == "low"
965+
else get_variable_trace_string(
966+
self.maker.inputs[i].variable
967967
)
968-
else:
969-
e.args = (
970-
"Bad input "
971-
+ argument_name
972-
+ " to "
973-
+ function_name
974-
+ f" at index {int(i)} (0-based). {where}"
975-
) + e.args
976-
self._restore_defaults()
977-
raise
968+
)
969+
raise ValueError(
970+
f"Invalid {argument_name} to {function_name} at index {i}.{where}"
971+
) from e
978972
arg_container.provided += 1
979973

980974
# Set keyword arguments

pytensor/configdefaults.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -638,15 +638,8 @@ def add_error_and_warning_configvars():
638638
# on all important apply nodes.
639639
config.add(
640640
"exception_verbosity",
641-
"If 'low', the text of exceptions will generally refer "
642-
"to apply nodes with short names such as "
643-
"Elemwise{add_no_inplace}. If 'high', some exceptions "
644-
"will also refer to apply nodes with long descriptions "
645-
""" like:
646-
A. Elemwise{add_no_inplace}
647-
B. log_likelihood_v_given_h
648-
C. log_likelihood_h""",
649-
EnumStr("low", ["high"]),
641+
"Verbosity of exceptions generated by PyTensor functions.",
642+
EnumStr("low", ["medium", "high"]),
650643
in_c_key=False,
651644
)
652645

0 commit comments

Comments
 (0)