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 21
21
from urllib .parse import urlencode
22
22
from urllib .parse import urlsplit
23
23
from urllib .parse import urlunsplit
24
-
25
24
except ImportError :
26
25
# Python 2
27
26
from cgi import parse_qs # type: ignore
30
29
from urlparse import urlsplit # type: ignore
31
30
from urlparse import urlunsplit # type: ignore
32
31
32
+ try :
33
+ # Python 3
34
+ FileNotFoundError
35
+ except NameError :
36
+ # Python 2
37
+ FileNotFoundError = IOError
38
+
33
39
try :
34
40
# Python 3.11
35
41
from builtins import BaseExceptionGroup
@@ -97,8 +103,8 @@ def _get_debug_hub():
97
103
98
104
def get_git_revision ():
99
105
# 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 :
102
108
revision = (
103
109
subprocess .Popen (
104
110
["git" , "rev-parse" , "HEAD" ],
@@ -110,8 +116,8 @@ def get_git_revision():
110
116
.strip ()
111
117
.decode ("utf-8" )
112
118
)
113
- except (OSError , IOError ):
114
- return None
119
+ except (OSError , IOError , FileNotFoundError ):
120
+ return None
115
121
116
122
return revision
117
123
Original file line number Diff line number Diff line change 6
6
Components ,
7
7
Dsn ,
8
8
get_error_message ,
9
+ get_git_revision ,
9
10
is_valid_sample_rate ,
10
11
logger ,
11
12
match_regex_list ,
25
26
except ImportError :
26
27
import mock # python < 3.3
27
28
29
+ try :
30
+ # Python 3
31
+ FileNotFoundError
32
+ except NameError :
33
+ # Python 2
34
+ FileNotFoundError = IOError
35
+
28
36
29
37
def _normalize_distribution_name (name ):
30
38
# type: (str) -> str
@@ -557,3 +565,17 @@ def test_installed_modules_caching():
557
565
558
566
_get_installed_modules ()
559
567
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