Skip to content

Commit

Permalink
fix: cgitb crashes if there is no line number set.
Browse files Browse the repository at this point in the history
I am not sure why:

  context.position[0]

is None when an exception happens while processing templates. This
causes a second exception because of a print statement matching %d to
None.  The second exception blows away any chance at getting useful
info.  So fix it by passing line number -1. Hopefully people will
recognize that as bogus and interpret it as no line number was
available.

Fixing the underlying cause (in ZopeTAL???) would be better though.
  • Loading branch information
rouilj committed Mar 13, 2024
1 parent a8a2610 commit a2918d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ Fixed:
request.client.additional_headers) to application/json and return
json from the template. This json could access the 1i18n functions
for a javascript helper. (John Rouillard)
- when template processing raises an exception the line number is
sometimes missing. This causes cgitb to raise a second exception
which clobbers the info about the template issue. As a stop-gap set
the line number to -1 so the original traceback can be seen. This
could be a bug in ZopeTAL. (John Rouillard)

Features:

Expand Down
2 changes: 1 addition & 1 deletion roundup/cgi/cgitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def pt_html(context=5, i18n=None):
</table></li>
''') % {
'info': info,
'line': context.position[0],
'line': context.position[0] or -1,
'globals': niceDict(' ', context.global_vars),
'locals': niceDict(' ', context.local_vars)
})
Expand Down

0 comments on commit a2918d4

Please sign in to comment.