🧹 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,17 +598,35 @@ class Main(Gtk.Window):
def run_app(self, app_cmd):
try:
# Run the application command with subprocess.run() and capture stdout and stderr
process = subprocess.run(
app_cmd,
shell=False,
shell=False, # Avoid shell injection
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
stderr=subprocess.PIPE, # Capture stderr separately
universal_newlines=True, # Ensure output is decoded as text
check=True # Raise CalledProcessError if command returns non-zero exit code
)
# for debugging print stdout to console
if GUI.debug is True:
# 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):
if widget.get_active() is True:
if os.path.isfile(GUI.dot_desktop):