🧹 chore: add better error handling

This commit is contained in:
eshanized
2025-01-01 09:18:46 +05:30
parent d78b83f8d6
commit 583c277c66

View File

@@ -598,16 +598,34 @@ class Main(Gtk.Window):
def run_app(self, app_cmd): def run_app(self, app_cmd):
process = subprocess.run( try:
app_cmd, # Run the application command with subprocess.run() and capture stdout and stderr
shell=False, process = subprocess.run(
stdout=subprocess.PIPE, app_cmd,
stderr=subprocess.STDOUT, shell=False, # Avoid shell injection
universal_newlines=True, stdout=subprocess.PIPE,
) stderr=subprocess.PIPE, # Capture stderr separately
# for debugging print stdout to console universal_newlines=True, # Ensure output is decoded as text
if GUI.debug is True: check=True # Raise CalledProcessError if command returns non-zero exit code
print(process.stdout) )
# Debugging: Print stdout to console if debugging is enabled
if GUI.debug:
print(process.stdout)
return process.stdout # Return the output
except subprocess.CalledProcessError as e:
# Handle errors in case the command fails (non-zero exit code)
if GUI.debug:
print(f"Error executing command: {e}")
return None # Return None on failure
except Exception as e:
# Catch any other exceptions
if GUI.debug:
print(f"Unexpected error: {e}")
return None
def startup_toggle(self, widget): def startup_toggle(self, widget):
if widget.get_active() is True: if widget.get_active() is True: