Skip to content

Commit 3fd150b

Browse files
committed
gracefully fail on bg completion conx issues
If we fail to make a connection for background completion refresh, catch the error and return without performing the refresh.
1 parent ee19a2b commit 3fd150b

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Features
66
* Allow styling prompts with HTML-like tags.
77

88

9+
Bug Fixes
10+
---------
11+
* Gracefully fail on background completion-refresh connection issues.
12+
13+
914
Documentation
1015
---------
1116
* Document the `\g` special command to send a query.

mycli/completion_refresher.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import threading
22
from typing import Callable
33

4+
import pymysql
5+
46
from mycli.packages.special.main import COMMANDS
57
from mycli.packages.sqlresult import SQLResult
68
from mycli.sqlcompleter import SQLCompleter
@@ -58,22 +60,25 @@ def _bg_refresh(
5860

5961
# Create a new sqlexecute method to populate the completions.
6062
e = sqlexecute
61-
executor = SQLExecute(
62-
e.dbname,
63-
e.user,
64-
e.password,
65-
e.host,
66-
e.port,
67-
e.socket,
68-
e.character_set,
69-
e.local_infile,
70-
e.ssl,
71-
e.ssh_user,
72-
e.ssh_host,
73-
e.ssh_port,
74-
e.ssh_password,
75-
e.ssh_key_filename,
76-
)
63+
try:
64+
executor = SQLExecute(
65+
e.dbname,
66+
e.user,
67+
e.password,
68+
e.host,
69+
e.port,
70+
e.socket,
71+
e.character_set,
72+
e.local_infile,
73+
e.ssl,
74+
e.ssh_user,
75+
e.ssh_host,
76+
e.ssh_port,
77+
e.ssh_password,
78+
e.ssh_key_filename,
79+
)
80+
except pymysql.err.OperationalError:
81+
return
7782

7883
# If callbacks is a single function then push it into a list.
7984
if callable(callbacks):

0 commit comments

Comments
 (0)