Skip to content

Commit b191703

Browse files
committed
better error messagge on connection
1 parent b2957cc commit b191703

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

gtk3/PCM.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ def _cleanup_askpass(path=_askpass):
700700
widget = TerminalWidget.da_profilo(dati, log_dir=log_dir)
701701
widget.comando_display = nome
702702
widget.comando_originale = cmd
703+
widget._tipo_sessione = dati.get("protocol", "ssh")
703704

704705
# SFTP browser laterale (solo SSH con sftp_browser attivo)
705706
if dati.get("sftp_browser") and dati.get("protocol") == "ssh":

gtk3/terminal_widget.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def __init__(self, bg="#1e1e1e", fg="#cccccc", font="Monospace",
7474
self._t_connessione = None
7575
self._char_inviati = 0
7676
self._comandi_inviati: list = []
77+
self._tipo_sessione = "locale"
78+
self._exit_code: int | None = None
7779

7880
self._init_ui()
7981

@@ -349,10 +351,34 @@ def _on_child_exited(self, terminal, status):
349351
GLib.source_remove(self._keepalive_source)
350352
self._keepalive_source = None
351353

352-
self._stato_testo = t("terminal.session_ended")
354+
if os.WIFEXITED(status):
355+
self._exit_code = os.WEXITSTATUS(status)
356+
elif os.WIFSIGNALED(status):
357+
self._exit_code = -(os.WTERMSIG(status))
358+
else:
359+
self._exit_code = None
360+
361+
if self._exit_code and self._exit_code != 0 and self._tipo_sessione != "locale":
362+
msg = self._exit_msg(self._exit_code)
363+
self._vte.feed(f"\r\n\x1b[1;33m[PCM] {msg}\x1b[0m\r\n".encode("utf-8"))
364+
self._stato_testo = f"✖ {msg}"
365+
else:
366+
self._stato_testo = t("terminal.session_ended")
367+
353368
self._stato_terminato = True
354369
self.emit("processo-terminato")
355370

371+
def _exit_msg(self, code: int) -> str:
372+
if self._tipo_sessione == "ssh":
373+
if code == 255:
374+
return t("terminal.exit.ssh_connection_error")
375+
if code < 0:
376+
return t("terminal.exit.signal", sig=-code)
377+
return t("terminal.exit.error_code", code=code)
378+
if code < 0:
379+
return t("terminal.exit.signal", sig=-code)
380+
return t("terminal.exit.error_code", code=code)
381+
356382
# ------------------------------------------------------------------
357383
# Cleanup
358384
# ------------------------------------------------------------------

gtk3/translations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ def init_from_settings() -> None:
375375

376376
# ── Terminale (VTE) ───────────────────────────────────────────────────────
377377
"terminal.session_ended": {"it": " ✖ Sessione terminata — clicca 'Riconnetti' o chiudi il tab", "en": " ✖ Session ended — click 'Reconnect' or close the tab", "de": " ✖ Sitzung beendet — 'Neu verbinden' klicken oder Tab schließen", "fr": " ✖ Session terminée — cliquez sur 'Reconnecter' ou fermez l'onglet", "es": " ✖ Sesión terminada — haz clic en 'Reconectar' o cierra la pestaña"},
378+
"terminal.exit.ssh_connection_error": {"it": "Errore di connessione — host irraggiungibile, porta chiusa o autenticazione fallita", "en": "Connection error — host unreachable, port closed, or authentication failed", "de": "Verbindungsfehler — Host nicht erreichbar, Port geschlossen oder Authentifizierung fehlgeschlagen", "fr": "Erreur de connexion — hôte inaccessible, port fermé ou authentification échouée", "es": "Error de conexión — host inalcanzable, puerto cerrado o autenticación fallida"},
379+
"terminal.exit.error_code": {"it": "Sessione terminata con errore (codice {code})", "en": "Session ended with error (code {code})", "de": "Sitzung mit Fehler beendet (Code {code})", "fr": "Session terminée avec erreur (code {code})", "es": "Sesión terminada con error (código {code})"},
380+
"terminal.exit.signal": {"it": "Processo terminato da segnale {sig}", "en": "Process killed by signal {sig}", "de": "Prozess durch Signal {sig} beendet", "fr": "Processus tué par le signal {sig}", "es": "Proceso terminado por señal {sig}"},
378381
"terminal.reconnect": {"it": "🔄 Riconnetti", "en": "🔄 Reconnect", "de": "🔄 Neu verbinden", "fr": "🔄 Reconnecter", "es": "🔄 Reconectar"},
379382
"terminal.vte_missing": {"it": "VTE non trovato. Installa gir1.2-vte-2.91", "en": "VTE not found. Install gir1.2-vte-2.91", "de": "VTE nicht gefunden. Installiere gir1.2-vte-2.91", "fr": "VTE introuvable. Installez gir1.2-vte-2.91", "es": "VTE no encontrado. Instala gir1.2-vte-2.91"},
380383
"terminal.deps_missing": {"it": "Dipendenze mancanti", "en": "Missing dependencies", "de": "Fehlende Abhängigkeiten", "fr": "Dépendances manquantes", "es": "Dependencias faltantes"},

0 commit comments

Comments
 (0)