Skip to content

Commit aac8a84

Browse files
committed
refactor(zypper.py): add error checking for subprocess calls
Signed-off-by: Wabri <[email protected]>
1 parent ae05027 commit aac8a84

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Diff for: zypper.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -210,22 +210,34 @@ def main(argv: Sequence[str] | None = None) -> int:
210210
['/usr/bin/zypper', '--quiet', 'lu'],
211211
stdout=subprocess.PIPE,
212212
check=False
213-
).stdout.decode('utf-8')
214-
data_zypper_lu = __extract_lu_data(raw_zypper_lu)
213+
)
214+
data_zypper_lu = []
215+
if raw_zypper_lu.returncode == 0:
216+
data_zypper_lu = __extract_lu_data(raw_zypper_lu.stdout.decode('utf-8'))
217+
else:
218+
raise RuntimeError("zypper returned exit code %d" % raw_zypper_lu.returncode)
215219

216220
raw_zypper_lp = subprocess.run(
217221
['/usr/bin/zypper', '--quiet', 'lp'],
218222
stdout=subprocess.PIPE,
219223
check=False
220-
).stdout.decode('utf-8')
221-
data_zypper_lp = __extract_lp_data(raw_zypper_lp)
224+
)
225+
data_zypper_lp = []
226+
if raw_zypper_lp.returncode == 0:
227+
data_zypper_lp = __extract_lp_data(raw_zypper_lp.stdout.decode('utf-8'))
228+
else:
229+
raise RuntimeError("zypper returned exit code %d" % raw_zypper_lp.returncode)
222230

223231
raw_zypper_orphaned = subprocess.run(
224232
['/usr/bin/zypper', '--quiet', 'pa', '--orphaned'],
225233
stdout=subprocess.PIPE,
226234
check=False
227-
).stdout.decode('utf-8')
228-
data_zypper_orphaned = __extract_orphaned_data(raw_zypper_orphaned)
235+
)
236+
data_zypper_orphaned = []
237+
if raw_zypper_orphaned.returncode == 0:
238+
data_zypper_orphaned = __extract_orphaned_data(raw_zypper_orphaned.stdout.decode('utf-8'))
239+
else:
240+
raise RuntimeError("zypper returned exit code %d" % raw_zypper_orphaned.returncode)
229241

230242
print_pending_updates(data_zypper_lu, args.all_info)
231243

0 commit comments

Comments
 (0)