File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -202,8 +202,7 @@ def _fstring_chunks(
202202 for node_value in arg_node .values :
203203 if isinstance (node_value , ast .Constant ):
204204 # These are the parts of the f-string not enclosed by `{}`, e.g. 'foo ' in f'foo {bar}'
205- value = node_value .value
206- assert type (value ) is str
205+ value : str = node_value .value
207206 result .append ({'v' : value , 't' : 'lit' })
208207 new_template += value
209208 else :
Original file line number Diff line number Diff line change 22
33import json
44import logging
5+ import os
56import sys
67from contextlib import contextmanager
78from pathlib import Path
@@ -226,6 +227,16 @@ def suppress_instrumentation():
226227
227228
228229def log_internal_error ():
230+ try :
231+ # Unless we're specifically testing this function, we should reraise the exception
232+ # in tests for easier debugging.
233+ current_test = os .environ .get ('PYTEST_CURRENT_TEST' , '' )
234+ reraise = bool (current_test and 'test_internal_exception' not in current_test )
235+ except Exception : # pragma: no cover
236+ reraise = False
237+ if reraise :
238+ raise
239+
229240 with suppress_instrumentation (): # prevent infinite recursion from the logging integration
230241 logger .exception ('Internal error in Logfire' )
231242
Original file line number Diff line number Diff line change 22import requests
33import requests_mock
44
5- from logfire ._internal .utils import UnexpectedResponse
5+ from logfire ._internal .utils import UnexpectedResponse , handle_internal_errors
66
77
88def test_raise_for_status () -> None :
@@ -15,3 +15,9 @@ def test_raise_for_status() -> None:
1515 s = str (exc_info .value )
1616 assert s .startswith ('Unexpected response 503' )
1717 assert 'body: this is the body' in s
18+
19+
20+ def test_reraise_internal_exception ():
21+ with pytest .raises (ZeroDivisionError ):
22+ with handle_internal_errors ():
23+ str (1 / 0 )
You can’t perform that action at this time.
0 commit comments