Skip to content

Commit 71dd744

Browse files
committed
Handle exceptions percisely
1 parent 96dcd7c commit 71dd744

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

quark/utils/tools.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ def get_rizin_version(rizin_path) -> Str:
129129
:return: the version number of the Rizin instance
130130
"""
131131
try:
132-
process = subprocess.run(
132+
result = subprocess.check_output(
133133
[rizin_path, "-v"], timeout=5, check=True, stdout=subprocess.PIPE
134134
)
135-
result = str(process.stdout)
136135

137136
matched_versions = re.finditer(
138137
r"[0-9]+\.[0-9]+\.[0-9]+", result[: result.index("@")]
@@ -144,7 +143,10 @@ def get_rizin_version(rizin_path) -> Str:
144143
else:
145144
return None
146145

147-
except BaseException:
146+
except subprocess.CalledProcessError:
147+
return None
148+
149+
except OSError:
148150
return None
149151

150152

@@ -178,7 +180,10 @@ def download_rizin(target_path) -> Boolean:
178180

179181
return True
180182

181-
except subprocess.CalledProcessError as error:
183+
except subprocess.CalledProcessError:
184+
print_error("An error occurred when downloading Rizin.\n")
185+
186+
except OSError:
182187
print_error("An error occurred when downloading Rizin.\n")
183188

184189
return False
@@ -242,12 +247,18 @@ def update_rizin(source_path, target_commit) -> Boolean:
242247
return True
243248

244249
except subprocess.CalledProcessError as error:
245-
print_error("An error occurred when updating Rizin.\n")
250+
pass
251+
except OSError:
252+
pass
246253

247-
for line in error.stderr.decode().splitlines():
248-
print_error(line)
254+
print_error("An error occurred when updating Rizin.\n")
249255

250-
return False
256+
for line in error.stderr.decode().splitlines():
257+
print_error(line)
258+
259+
print_error("An error occurred when downloading Rizin.\n")
260+
261+
return False
251262

252263

253264
def find_rizin_instance(

0 commit comments

Comments
 (0)