File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed
Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Original file line number Diff line number Diff line change 2121 from urllib .parse import urlencode
2222 from urllib .parse import urlsplit
2323 from urllib .parse import urlunsplit
24-
2524except ImportError :
2625 # Python 2
2726 from cgi import parse_qs # type: ignore
3029 from urlparse import urlsplit # type: ignore
3130 from urlparse import urlunsplit # type: ignore
3231
32+ try :
33+ # Python 3
34+ FileNotFoundError
35+ except NameError :
36+ # Python 2
37+ FileNotFoundError = IOError
38+
3339try :
3440 # Python 3.11
3541 from builtins import BaseExceptionGroup
@@ -97,8 +103,8 @@ def _get_debug_hub():
97103
98104def get_git_revision ():
99105 # type: () -> Optional[str]
100- with open ( os . path . devnull , "w+" ) as null :
101- try :
106+ try :
107+ with open ( os . path . devnull , "w+" ) as null :
102108 revision = (
103109 subprocess .Popen (
104110 ["git" , "rev-parse" , "HEAD" ],
@@ -110,8 +116,8 @@ def get_git_revision():
110116 .strip ()
111117 .decode ("utf-8" )
112118 )
113- except (OSError , IOError ):
114- return None
119+ except (OSError , IOError , FileNotFoundError ):
120+ return None
115121
116122 return revision
117123
Original file line number Diff line number Diff line change 66 Components ,
77 Dsn ,
88 get_error_message ,
9+ get_git_revision ,
910 is_valid_sample_rate ,
1011 logger ,
1112 match_regex_list ,
2526except ImportError :
2627 import mock # python < 3.3
2728
29+ try :
30+ # Python 3
31+ FileNotFoundError
32+ except NameError :
33+ # Python 2
34+ FileNotFoundError = IOError
35+
2836
2937def _normalize_distribution_name (name ):
3038 # type: (str) -> str
@@ -557,3 +565,17 @@ def test_installed_modules_caching():
557565
558566 _get_installed_modules ()
559567 mock_generate_installed_modules .assert_not_called ()
568+
569+
570+ def test_devnull_inaccessible ():
571+ with mock .patch ("sentry_sdk.utils.open" , side_effect = OSError ("oh no" )):
572+ revision = get_git_revision ()
573+
574+ assert revision is None
575+
576+
577+ def test_devnull_not_found ():
578+ with mock .patch ("sentry_sdk.utils.open" , side_effect = FileNotFoundError ("oh no" )):
579+ revision = get_git_revision ()
580+
581+ assert revision is None
You can’t perform that action at this time.
0 commit comments