Skip to content

Commit ce87ff3

Browse files
committed
Manage error when running needrestart.
Signed-off-by: RomainMou <[email protected]>
1 parent 2e1fae3 commit ce87ff3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Diff for: needrestart_info.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,17 @@ def write_sessions(registry, needrestart_data):
145145
def main():
146146
registry = CollectorRegistry()
147147

148-
needrestart_output = subprocess.run(
149-
["needrestart", "-b"], capture_output=True, text=True
150-
).stdout
151-
needrestart_data = NeedRestartData(needrestart_output)
148+
try:
149+
needrestart_output = subprocess.run(
150+
["needrestart", "-b"], capture_output=True, text=True, check=True
151+
).stdout
152+
needrestart_data = NeedRestartData(needrestart_output)
153+
except subprocess.CalledProcessError as e:
154+
print(f"Error executing needrestart:\n{e}")
155+
sys.exit(1)
156+
except Exception as e:
157+
print(f"An unexpected error occurred:\n{e}")
158+
sys.exit(1)
152159

153160
write_timestamp(registry, needrestart_data)
154161
write_kernel(registry, needrestart_data)

0 commit comments

Comments
 (0)