Repository: spyder-ide/spyder
Pull request: PR: Catch error when trying to connect to a non-existing connection file (IPython console)
<!--- Make sure to read the Contributing Guidelines:                   --->
<!--- https://github.com/spyder-ide/spyder/blob/master/CONTRIBUTING.md --->
<!--- and follow PEP 8, PEP 257 and Spyder's code style:               --->
<!--- https://github.com/spyder-ide/spyder/wiki/Dev:-Coding-Style      --->

## Description of Changes





<!--- Explain what you've done and why --->




### Issue(s) Resolved

<!--- List the issue(s) below, in the form "Fixes #1234"; one per line --->

Fixes #23729


### Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the [Developer Certificate of Origin](https://developercertificate.org)
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

<!--- TYPE YOUR USER/NAME AFTER THE FOLLOWING: --->
I certify the above statement is true and correct:

@jsbautista 
<!--- Thanks for your help making Spyder better for everyone! --->


Problem statement:
`TypeError: 'in <string>' requires string as left operand, not NoneType` when connecting to an existing kernel
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Consoles/Connect to kernel python 3.13 :An error occurred while starting the kernel
It was not possible to connect to the kernel associated to this console. If you are trying to connect to an existing kernel, check that the connection file you selected actually corresponds to the kernel you want to connect to.

### Traceback
```python-traceback
Traceback (most recent call last):
  File "C:\Users\Horia\AppData\Local\Programs\Python\Python313\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\main_widget.py", line 1187, in _create_client_for_kernel
    self.create_client_for_kernel(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        connection_file, hostname, sshkey, password)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Horia\AppData\Local\Programs\Python\Python313\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\main_widget.py", line 1754, in create_client_for_kernel
    if cl.connection_file and connection_file in cl.connection_file:
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'in <string>' requires string as left operand, not NoneType
```

## Versions

* Spyder version: 6.0.4  (pip)
* Python version: 3.13.1 64-bit
* Qt version: 5.15.2
* PyQt5 version: 5.15.11
* Operating System: Windows-10-10.0.19045-SP0

### Dependencies

```
# Mandatory:
aiohttp >=3.9.3                  :  3.11.11 (OK)
asyncssh >=2.14.0,<3.0.0         :  2.19.0 (OK)
atomicwrites >=1.2.0             :  1.4.1 (OK)
chardet >=2.0.0                  :  3.0.4 (OK)
cloudpickle >=0.5.0              :  3.1.0 (OK)
cookiecutter >=1.6.0             :  2.6.0 (OK)
diff_match_patch >=20181111      :  20241021 (OK)
github >=2.3.0                   :  2.5.0 (OK)
importlib_metadata >=4.6.0       :  8.5.0 (OK)
intervaltree >=3.0.2             :  3.1.0 (OK)
IPython >=8.13.0,<9.0.0,!=8.17.1 :  8.31.0 (OK)
jedi >=0.17.2,<0.20.0            :  0.19.2 (OK)
jellyfish >=0.7                  :  1.1.3 (OK)
jsonschema >=3.2.0               :  4.23.0 (OK)
keyring >=17.0.0                 :  25.6.0 (OK)
nbconvert >=4.0                  :  7.16.5 (OK)
numpydoc >=0.6.0                 :  1.8.0 (OK)
parso >=0.7.0,<0.9.0             :  0.8.4 (OK)
pexpect >=4.4.0                  :  4.9.0 (OK)
pickleshare >=0.4                :  0.7.5 (OK)
psutil >=5.3                     :  6.1.1 (OK)
pygments >=2.0                   :  2.19.1 (OK)
pylint >=3.1,<4                  :  3.3.3 (OK)
pylint_venv >=3.0.2              :  3.0.4 (OK)
pyls_spyder >=0.4.0              :  0.4.0 (OK)
pylsp >=1.12.0,<1.13.0           :  1.12.0 (OK)
pylsp_black >=2.0.0,<3.0.0       :  2.0.0 (OK)
pyuca >=1.2                      :  1.2 (OK)
qdarkstyle >=3.2.0,<3.3.0        :  3.2.3 (OK)
qstylizer >=0.2.2                :  0.2.4 (OK)
qtawesome >=1.3.1,<1.4.0         :  1.3.1 (OK)
qtconsole >=5.6.1,<5.7.0         :  5.6.1 (OK)
qtpy >=2.4.0                     :  2.4.2 (OK)
rtree >=0.9.7                    :  1.3.0 (OK)
setuptools >=49.6.0              :  75.8.0 (OK)
sphinx >=0.6.6                   :  8.1.3 (OK)
spyder_kernels >=3.0.3,<3.1.0    :  3.0.3 (OK)
superqt >=0.6.2,<1.0.0           :  0.7.1 (OK)
textdistance >=4.2.0             :  4.6.2 (OK)
three_merge >=0.1.1              :  0.1.1 (OK)
watchdog >=0.10.3                :  6.0.0 (OK)
yarl >=1.9.4                     :  1.18.3 (OK)
zmq >=24.0.0                     :  26.2.0 (OK)

# Optional:
cython >=0.21                    :  3.0.11 (OK)
matplotlib >=3.0.0               :  3.10.0 (OK)
numpy >=1.7                      :  2.1.3 (OK)
pandas >=1.1.1                   :  2.2.3 (OK)
scipy >=0.17.0                   :  1.15.1 (OK)
sympy >=0.7.3                    :  1.13.1 (OK)
```

### Environment

<details><summary>Environment</summary>

```
Package                        Version
------------------------------ ---------------
absl-py                        2.1.0
aiohappyeyeballs               2.4.4
aiohttp                        3.11.11
aiosignal                      1.3.2
alabaster                      1.0.0
algoliasearch                  4.12.0
altgraph                       0.17.4
annotated-types                0.7.0
antigravity                    0.1
any                            0.0.1
anyio                          4.8.0
anytree                        2.12.1
appdirs                        1.4.4
argcomplete                    1.12.3
argon2-cffi                    23.1.0
argon2-cffi-bindings           21.2.0
arrayfire                      3.8.0
arrow                          1.3.0
asciitree                      0.3.3
asgiref                        3.8.1
aspose-words                   25.1.0
astroid                        3.3.8
asttokens                      3.0.0
astunparse                     1.6.3
async-generator                1.10
async-lru                      2.0.4
async-timeout                  5.0.1
asyncio                        3.4.3
asyncssh                       2.19.0
atomicwrites                   1.4.1
attr                           0.3.2
attrs                          24.3.0
audioop-lts                    0.2.1
audioread                      3.0.1
autobahn                       24.4.2
autocommand                    2.2.2
autolab-core                   1.1.1
Automat                        24.8.1
autopep8                       2.0.4
autoreload                     0.1.2
awesomeversion                 24.6.0
babel                          2.16.0
backcall                       0.2.0
backoff                        2.2.1
base-test                      0.1
beautifulsoup4                 4.12.3
betterproto                    2.0.0b6
binaryornot                    0.4.4
biopython                      1.85
bitarray                       3.0.0
black                          24.10.0
bleach                         6.2.0
blinker                        1.9.0
blis                           1.1.0
blosc2                         3.0.0
boto3                          1.35.98
botocore                       1.35.98
bottle                         0.12.18
bs4                            0.0.2
bson                           0.5.10
build                          1.2.2.post1
bz2file                        0.98
cached-property                2.0.1
cachelib                       0.9.0
cachetools                     5.5.0
cairocffi                      1.7.1
CairoSVG                       2.7.1
cambridict                     0.1.6
camelot-py                     1.0.0
camera                         1.3.0
catalogue                      2.0.10
cattrs                         24.1.2
certifi                        2024.12.14
cffi                           1.17.1
cfgv                           3.4.0
chardet                        3.0.4
charset-normalizer             3.4.1
cheroot                        10.0.1
CherryPy                       18.10.0
chill                          0.10.1
clang                          17.0.6
clean-text                     0.6.0
cliar                          1.3.5
click                          8.1.8
cloudpathlib                   0.20.0
cloudpickle                    3.1.0
cmake                          3.31.4
cocos                          0.2.2
codegen                        1.19.0
codegen-types                  0.271.0
colorama                       0.4.6
colorclass                     2.2.2
colordict                      1.2.6
coloredlogs                    15.0.1
colorlog                       6.9.0
columnize                      0.3.11
comm                           0.2.2
compressed_rtf                 1.0.6
comtypes                       1.4.9
confection                     0.1.5
configobj                      5.0.9
configparser                   7.1.0
conllu                         6.0.0
constantly                     23.10.4
constants                      0.6.0
contexttimer                   0.3.3
contextvars                    2.4
contourpy                      1.3.1
convert                        0.1.2
cookiecutter                   2.6.0
cookiejar                      0.0.3
coverage                       7.6.10
crayons                        0.4.0
crypto                         1.4.1
cryptography                   44.0.0
cssselect                      1.2.0
cssselect2                     0.7.0
cssutils                       2.11.1
csvprint                       0.7.1
cycler                         0.12.1
cymem                          2.0.10
Cython                         3.0.11
cytoolz                        1.0.1
dask                           2024.12.1
dataclasses                    0.6
DateTime                       5.5
debugpy                        1.8.11
decorator                      5.1.1
deep-translator                1.11.4
deepmerge                      2.0
defusedxml                     0.7.1
Deprecated                     1.2.15
deprecation                    2.1.0
develop                        0.2.1
dicom2jpg                      0.1.10
diff-match-patch               20241021
dill                           0.3.9
dis                            1.0.1
distlib                        0.3.9
distro                         1.9.0
dnspython                      2.7.0
docker                         7.1.0
docopt                         0.6.2
docstring-to-markdown          0.15
docutils                       0.21.2
docx                           0.2.4
docx2txt                       0.8
drawtree                       0.1.2
easygui                        0.98.3
ebcdic                         1.1.1
Elixir                         0.7.1
email_validator                2.2.0
emoji                          1.7.0
enchant                        0.0.1
entrypoints                    0.4
et_xmlfile                     2.0.0
ete3                           3.1.3
eth_abi                        5.2.0
eth-hash                       0.7.1
eth-typing                     5.1.0
eth-utils                      5.1.0
etils                          1.11.0
eutils                         0.6.0
examples                       1.0.2
exceptiongroup                 1.2.2
executing                      2.1.0
ExtensionClass                 6.0
extract-msg                    0.52.0
ezdxf                          1.3.5
face_recognition_models        0.3.0
fasteners                      0.19
fastjsonschema                 2.21.1
fastrlock                      0.8.3
ffmpeg                         1.4
ffmpeg-python                  0.2.0
ffmpy                          0.5.0
filelock                       3.16.1
fire                           0.7.0
flake8                         7.1.1
Flask                          3.1.0
Flask-Caching                  2.3.0
Flask-Markdown                 0.3
flatbuffers                    24.12.23
fonttools                      4.55.3
fqdn                           1.5.1
fr                             3.1
freetype-py                    2.5.1
Frozen-Flask                   1.0.2
frozenlist                     1.5.0
fsspec                         2024.12.0
ftfy                           6.3.1
future                         1.0.0
gast                           0.6.0
german                         0.1.0
german-lemmatizer              0.1.1
gevent                         24.11.1
ghostscript                    0.7
gitdb                          4.0.12
GitPython                      3.1.44
giturlparse                    0.12.0
glfw                           2.8.0
google-api-core                2.24.0
google-api-python-client       2.159.0
google-auth                    2.37.0
google-auth-httplib2           0.2.0
google-auth-oauthlib           1.2.1
google-pasta                   0.2.0
googleapis-common-protos       1.66.0
graph-sitter-types             6.2.4
graphlib                       0.9.5
graphviz                       0.20.3
greenlet                       3.1.1
grpcio                         1.69.0
grpclib                        0.4.7
h11                            0.14.0
h2                             4.2.0
h5py                           3.12.1
habanero                       2.0.0
HanTa                          1.1.1
hpack                          4.1.0
HTMLParser                     0.0.2
httpcore                       1.0.7
httplib2                       0.22.0
httpx                          0.28.1
huggingface-hub                0.27.1
humanfriendly                  10.0
humanize                       4.11.0
hyperframe                     6.1.0
hyperlink                      21.0.0
hypothesis                     6.123.17
icecream                       2.1.4
id                             1.5.0
identify                       2.6.5
idna                           2.10
ImageHash                      4.3.1
imageio                        2.36.1
imageio-ffmpeg                 0.5.1
imagesize                      1.4.1
IMAPClient                     3.0.1
img2pdf                        0.5.1
immutables                     0.21
importlib_metadata             8.5.0
importlib_resources            6.5.2
in-toto-attestation            0.9.3
inflect                        7.5.0
inflection                     0.5.1
iniconfig                      2.0.0
intervaltree                   3.1.0
ipaddress                      1.0.23
ipykernel                      6.29.5
ipynb-py-convert               0.4.6
ipyparallel                    9.0.0
ipython                        8.31.0
ipython-genutils               0.2.0
ipywidgets                     8.1.5
isoduration                    20.11.0
isort                          5.13.2
itsdangerous                   2.2.0
jaraco.classes                 3.4.0
jaraco.collections             5.1.0
jaraco.context                 6.0.1
jaraco.functools               4.1.0
jaraco.text                    4.0.0
jax                            0.4.38
jaxlib                         0.4.38
jedi                           0.19.2
jellyfish                      1.1.3
Jinja2                         3.1.5
jinja2-time                    0.2.0
jiter                          0.8.2
jmespath                       1.0.1
joblib                         1.4.2
jpype1                         1.5.1
json5                          0.10.0
jsonpointer                    3.0.0
jsonschema                     4.23.0
jsonschema-specifications      2024.10.1
jupyter                        1.1.1
jupyter_client                 8.6.3
jupyter-console                6.6.3
jupyter_core                   5.7.2
jupyter-events                 0.11.0
jupyter-lsp                    2.2.5
jupyter_server                 2.15.0
jupyter_server_terminals       0.5.3
jupyterlab                     4.3.4
jupyterlab_pygments            0.3.0
jupyterlab_server              2.27.3
jupyterlab_widgets             3.0.13
jupytext                       1.16.6
kagglehub                      0.3.7
kaleido                        0.2.1
keras                          3.8.0
keyring                        25.6.0
kiwisolver                     1.4.8
knime                          0.11.6
langcodes                      3.5.0
language_data                  1.3.0
lark                           1.1.9
lark-parser                    0.12.0
lazy_loader                    0.4
Levenshtein                    0.26.1
libclang                       18.1.1
line_profiler                  4.2.0
llvmlite                       0.44.0
locket                         1.0.0
loky                           3.4.1
lxml                           5.3.0
lxml_html_clean                0.4.1
mailbox                        0.4
manifold3d                     3.0.1
mapbox_earcut                  1.0.3
marisa-trie                    1.2.1
Markdown                       3.7
markdown-it-py                 3.0.0
MarkupSafe                     3.0.2
matplotlib                     3.10.0
matplotlib-inline              0.1.7
mccabe                         0.7.0
mdit-py-plugins                0.4.2
mdurl                          0.1.2
metapub                        0.5.12
mistune                        3.1.0
ml-datasets                    0.2.0
ml_dtypes                      0.5.1
mock                           5.1.0
model-signing                  0.2.0
modules                        1.0.0
monotonic                      1.6
more                           0.0.1b14
more-itertools                 10.6.0
MouseInfo                      0.1.3
moviepy                        2.1.2
mpmath                         1.3.0
msgpack                        1.1.0
msoffcrypto-tool               5.4.2
mujoco                         3.2.6
mujoco-py                      2.1.2.14
multidict                      6.1.0
multiprocess                   0.70.17
murmurhash                     1.0.11
mypy                           1.14.1
mypy-extensions                1.0.0
mysql                          0.0.3
mysql-connector-python         9.1.0
mysqlclient                    2.2.7
MySQLX                         2.2.8
Naked                          0.1.32
namex                          0.0.8
nbclassic                      1.1.0
nbclient                       0.10.2
nbconvert                      7.16.5
nbformat                       5.10.4
ndindex                        1.9.2
nest-asyncio                   1.6.0
networkx                       3.4.2
nh3                            0.2.20
ninja                          1.11.1.3
nltk                           3.9.1
nodeenv                        1.9.1
notebook                       7.3.2
notebook_shim                  0.2.4
numba                          0.61.0
numexpr                        2.10.2
numpy                          2.1.3
numpydoc                       1.8.0
oauthlib                       3.2.2
olefile                        0.47
oletools                       0.60.2
openai                         1.59.7
opencv-contrib-python          4.10.0.84
opencv-contrib-python-headless 4.10.0.84
opencv-python                  4.10.0.84
opencv-python-headless         4.10.0.84
openpyxl                       3.1.5
opt_einsum                     3.4.0
optree                         0.13.1
orca                           1.8
outcome                        1.3.0.post0
overrides                      7.7.0
p2j                            1.3.2
packaging                      23.2
pager                          3.3
pandas                         2.2.3
pandocfilters                  1.5.1
parse                          1.20.2
parsel                         1.9.1
parsimonious                   0.10.0
parso                          0.8.4
partd                          1.4.2
pasta                          0.2
pathlib                        1.0.1
pathlib_abc                    0.1.1
pathos                         0.3.3
pathspec                       0.12.1
pathy                          0.11.0
patsy                          1.0.1
pbr                            6.1.0
pcodedmp                       1.2.6
pdf2docx                       0.5.8
pdf2image                      1.17.0
pdf2jpg                        1.1
pdf2text                       1.0.0
pdfkit                         1.0.0
pdfminer                       20191125
pdfminer.six                   20231228
pdfplumber                     0.11.5
pdfreader                      0.1.15
pefile                         2023.2.7
perfmon                        0.0.3
peutils                        0.0.122
pexpect                        4.9.0
pickleshare                    0.7.5
pikepdf                        9.5.1
pillow                         10.4.0
pip                            25.0.1
pkginfo                        1.12.0
platformdirs                   4.3.6
plotly                         5.24.1
plotly-utils                   0.0.3
pluggy                         1.5.0
poppler-utils                  0.1.0
portend                        3.2.0
poser                          0.2.3
posthog                        3.8.3
pox                            0.3.5
ppft                           1.7.6.9
pre_commit                     4.0.1
prettytable                    0.7.2
proglog                        0.1.10
prometheus_client              0.21.1
prompt_toolkit                 3.0.48
propcache                      0.2.1
proto-plus                     1.25.0
protobuf                       5.29.3
psutil                         6.1.1
ptyprocess                     0.7.0
pure_eval                      0.2.3
py                             1.11.0
py-cpuinfo                     9.0.0
py-solc-x                      2.0.3
pyasn1                         0.6.1
pyasn1_modules                 0.4.1
PyAudio                        0.2.14
pyautocad                      0.2.0
PyAutoGUI                      0.9.54
pybind11                       2.13.6
pyclipper                      1.3.0.post6
pycodestyle                    2.12.1
pycollada                      0.8
pycparser                      2.22
pycryptodome                   3.21.0
pydantic                       2.10.5
pydantic_core                  2.27.2
PyDecimal                      1.0
pydicom                        3.0.1
pydocstyle                     6.3.0
pydot                          3.0.4
pydub                          0.25.1
pyee                           11.1.1
pyflakes                       3.2.0
pygame                         2.6.1
PyGetWindow                    0.0.9
pygit                          0.1
pygit2                         1.17.0
PyGithub                       2.5.0
pyglet                         2.1.0
Pygments                       2.19.1
PyHamcrest                     2.0.2
pyinsane                       1.4.0
pyinstaller                    6.11.1
pyinstaller-hooks-contrib      2024.11
pyio                           0.1.1
pyipp                          0.17.0
PyJWT                          2.10.1
pylibjpeg                      2.0.1
pylibjpeg-libjpeg              2.3.0
pylibjpeg-openjpeg             2.4.0
pylint                         3.3.3
pylint-venv                    3.0.4
pyls-spyder                    0.4.0
pymongo                        3.11.0
PyMsgBox                       1.0.9
PyMuPDF                        1.25.1
pymupdf-fonts                  1.0.5
PyNaCl                         1.5.0
pynput                         1.7.7
PyOpenGL                       3.1.0
pyOpenSSL                      25.0.0
pyparsing                      3.2.1
pypdf                          5.1.0
PyPDF2                         3.0.1
PyPDF4                         1.27.0
pypdfium2                      4.30.1
pyperclip                      1.9.0
pyppeteer                      2.0.0
pyproject_hooks                1.2.0
PyQt5                          5.15.11
PyQt5-Qt5                      5.15.2
PyQt5_sip                      12.16.1
PyQtWebEngine                  5.15.7
PyQtWebEngine-Qt5              5.15.2
pyreadline                     2.1
pyreadline3                    3.5.4
PyRect                         0.2.0
pyrender                       0.1.45
pyrsistent                     0.20.0
pysbd                          0.3.4
pyscan                         1.0.0
PyScreeze                      1.0.1
PySocks                        1.7.1
PySynonym                      0.0.9
pytesseract                    0.3.13
pytest                         5.4.3
pytest-timeout                 2.3.1
python-bidi                    0.6.3
python-dateutil                2.9.0.post0
python-docx                    1.1.2
python-dotenv                  1.0.1
python-git                     2018.2.1
python-hglib                   2.6.2
python-json-logger             3.2.1
python-Levenshtein             0.26.1
python-lsp-black               2.0.0
python-lsp-jsonrpc             1.1.2
python-lsp-server              1.12.0
python-pptx                    1.0.2
python-slugify                 8.0.4
pytils                         0.4.1
pytoolconfig                   1.3.1
pytwain                        2.3.0
pytweening                     1.2.0
pytz                           2024.2
pytz-deprecation-shim          0.1.0.post0
pyuca                          1.2
PyWavefront                    1.3.3
PyWavelets                     1.8.0
pywin32                        308
pywin32-ctypes                 0.2.3
pywinpty                       2.0.14
PyYAML                         6.0.2
pyzmq                          26.2.0
QDarkStyle                     3.2.3
qstylizer                      0.2.4
QtAwesome                      1.3.1
qtconsole                      5.6.1
QtPy                           2.4.2
RapidFuzz                      3.11.0
readme_renderer                44.0
Record                         4.1
red-black-tree-mod             1.20
referencing                    0.35.1
regex                          2024.11.6
repo                           0.3.0
requests                       2.32.3
requests-oauthlib              2.0.0
requests-toolbelt              1.0.0
rfc3161-client                 0.1.2
rfc3339-validator              0.1.4
rfc3986                        2.0.0
rfc3986-validator              0.1.1
rfc8785                        0.1.4
rich                           13.9.4
rich-click                     1.8.5
rope                           1.13.0
rpds-py                        0.22.3
rsa                            4.9
RTFDE                          0.1.2
Rtree                          1.3.0
ruamel.showoutput              0.1.7
ruamel.yaml                    0.18.10
ruff                           0.9.3
rustworkx                      0.15.1
s3transfer                     0.10.4
safetensors                    0.5.2
scikit-build                   0.18.1
scikit-image                   0.25.0
scikit-learn                   1.6.1
scipy                          1.15.1
seaborn                        0.13.2
securesystemslib               1.2.0
selectors                      0.0.14
selenium                       4.27.1
Send2Trash                     1.8.3
servicemanager                 2.0.10
setproctitle                   1.3.4
setuptools                     75.8.0
sha1                           1.2
shapely                        2.0.6
shellescape                    3.8.1
shellingham                    1.5.4
sigstore                       3.6.1
sigstore-protobuf-specs        0.3.2
sigstore-rekor-types           0.0.18
six                            1.17.0
slugify                        0.0.1
smart-open                     6.4.0
smmap                          5.0.2
sniffio                        1.3.1
snowballstemmer                2.2.0
socks                          0
sortedcontainers               2.4.0
soundfile                      0.13.0
soupsieve                      2.6
spacy-legacy                   3.0.12
spacy-loggers                  1.0.5
SpeechRecognition              3.14.0
Sphinx                         8.1.3
sphinxcontrib-applehelp        2.0.0
sphinxcontrib-devhelp          2.0.0
sphinxcontrib-htmlhelp         2.1.0
sphinxcontrib-jsmath           1.0.1
sphinxcontrib-qthelp           2.0.0
sphinxcontrib-serializinghtml  2.0.0
sprite                         0.1.0
spyder                         6.0.4
spyder-kernels                 3.0.3
SQLAlchemy                     2.0.37
sqlalchemy-migrate             0.13.0
sqlexecutorx                   1.8.2
SQLExecX                       2.1.8
sqlparse                       0.5.3
sqlx-batis                     2.1.4
sqlx-exec                      2.3.8
sqlx-executor                  1.1.6
srsly                          2.5.0
stack-data                     0.6.3
standard-aifc                  3.13.0
standard-chunk                 3.13.0
stanza                         0.3
statistics                     1.0.3.5
statsmodels                    0.14.4
summary                        0.2.0
superqt                        0.7.1
sympy                          1.13.1
tables                         3.10.2
tabula                         1.0.5
tabula-py                      2.10.0
tabulate                       0.9.0
Tempita                        0.6.0
tempora                        5.8.0
tenacity                       9.0.0
tensorboard                    2.18.0
tensorboard-data-server        0.7.2
tensorboard-plugin-wit         1.8.1
tensorflow-estimator           2.15.0
tensorflow-intel               0.0.1
termcolor                      2.5.0
terminado                      0.18.1
tesseract                      0.1.3
text-unidecode                 1.3
textblob                       0.19.0
textdistance                   4.6.3
the                            0.1.5
threadpoolctl                  3.5.0
three-merge                    0.1.1
tifffile                       2025.1.10
tiler                          0.5.7
timer                          0.3.0
tinycss2                       1.4.0
tinytag                        2.0.0
to                             0.3
tokenizers                     0.21.0
toml                           0.10.2
tomli                          2.2.1
tomlkit                        0.13.2
toolz                          1.0.0
torch                          2.6.0
tornado                        6.4.2
tqdm                           4.67.1
traitlets                      5.14.3
transformers                   4.48.0
treelib                        1.7.0
trimesh                        4.5.3
trio                           0.28.0
trio-websocket                 0.11.1
tuf                            5.1.0
twine                          6.0.1
txaio                          23.1.1
typeguard                      4.4.1
typer                          0.15.1
types-mock                     5.1.0.20240425
types-networkx                 3.4.2.20241227
types-python-dateutil          2.9.0.20241206
types-requests                 2.32.0.20241016
types-setuptools               75.8.0.20250110
typing                         3.7.4.3
typing_extensions              4.12.2
tzdata                         2024.2
tzlocal                        5.2
ujson                          5.10.0
Unidecode                      1.3.8
uri-template                   1.3.0
uritemplate                    4.1.1
urllib3                        2.3.0
user_agent                     0.1.10
uuid                           1.30
uv                             0.5.18
vectorize                      0.2.0
vedo                           2024.5.2
virtualenv                     20.28.1
visualizer                     0.0.10
vtk                            9.4.1
w3lib                          2.2.1
Wand                           0.6.13
wasabi                         1.1.3
watchdog                       6.0.0
Wave                           0.0.2
wavefront_reader               0.2.2
wcwidth                        0.2.13
weakrefset                     1.0.0
weasel                         0.4.1
webcolors                      24.11.1
webdriver-manager              4.0.2
webencodings                   0.5.1
weblib                         0.1.30
websocket-client               1.8.0
websockets                     10.4
Werkzeug                       3.1.3
whatthepatch                   1.0.7
wheel                          0.45.1
widgetsnbextension             4.0.13
wiktionaryparser               0.0.97
win_unicode_console            0.5
Win32Security                  2.1.0
winapi                         0.0.0
wkhtmltopdf                    0.2
word2vec                       0.11.1
wordcloud                      1.9.4
wrapt                          1.17.2
wsproto                        1.2.0
xlrd                           2.0.1
XlsxWriter                     3.2.0
xlwt                           1.3.0
xxhash                         3.5.0
yapf                           0.43.0
yarl                           1.18.3
zc.lockfile                    3.0.post1
zipp                           3.21.0
zmq                            0.0.0
zope.event                     5.0
zope.interface                 7.2
zstandard                      0.23.0

```
</details>

Hints from issue discussion:
Hi @hgeorgescu thank you for the report! I think I was able to reproduce this. We will give it a check in a future release :+1:

For reference, a preview of the error:

![Image](https://github.com/user-attachments/assets/66b112ad-c405-4ce4-9c8e-a57842f34129)

Probably we need to add some logic to prevent the dialog `OK` button to be active unless a connection file is defined/selected 🤔

Commit message: Update spyder/plugins/ipythonconsole/widgets/kernelconnect.py

Co-authored-by: Carlos Cordoba <ccordoba12@gmail.com>

Patch to review:
diff --git a/spyder/plugins/ipythonconsole/widgets/kernelconnect.py b/spyder/plugins/ipythonconsole/widgets/kernelconnect.py
index db90a1659bd..ae2f03a17f7 100644
--- a/spyder/plugins/ipythonconsole/widgets/kernelconnect.py
+++ b/spyder/plugins/ipythonconsole/widgets/kernelconnect.py
@@ -12,13 +12,14 @@
 import os.path as osp
 
 # Third party imports
+from jupyter_client.connect import find_connection_file
 from jupyter_core.paths import jupyter_runtime_dir
 from qtpy.compat import getopenfilename
 from qtpy.QtCore import Qt
 from qtpy.QtWidgets import (QCheckBox, QDialog, QDialogButtonBox, QGridLayout,
-                            QGroupBox, QHBoxLayout, QLabel, QLineEdit,
-                            QPushButton, QRadioButton, QSpacerItem,
-                            QVBoxLayout)
+                            QGroupBox, QHBoxLayout, QLabel, QLineEdit, 
+                            QMessageBox, QPushButton, QRadioButton, 
+                            QSpacerItem, QVBoxLayout)
 
 # Local imports
 from spyder.api.config.mixins import SpyderConfigurationAccessor
@@ -55,6 +56,9 @@ def __init__(self, parent=None):
         cf_open_btn = QPushButton(_('Browse'))
         cf_open_btn.clicked.connect(self.select_connection_file)
 
+        # Signals
+        self.cf.textChanged.connect(self.activate_button)
+
         cf_layout = QHBoxLayout()
         cf_layout.addWidget(cf_label)
         cf_layout.addWidget(self.cf)
@@ -142,9 +146,11 @@ def __init__(self, parent=None):
             Qt.Horizontal,
             self,
         )
+        self.button_ok = self.accept_btns.button(QDialogButtonBox.Ok)
+        self.button_ok.setEnabled(False)
 
         self.accept_btns.accepted.connect(self.save_connection_settings)
-        self.accept_btns.accepted.connect(self.accept)
+        self.accept_btns.accepted.connect(self._validate_connection_file)
         self.accept_btns.rejected.connect(self.reject)
 
         # Save connection settings checkbox
@@ -167,6 +173,12 @@ def __init__(self, parent=None):
         self.cf.setFocus()
         self.load_connection_settings()
 
+    def activate_button(self):
+        if self.cf.text() == "":
+            self.button_ok.setEnabled(False)
+        else:
+            self.button_ok.setEnabled(True)
+
     def load_connection_settings(self):
         """Load the user's previously-saved kernel connection settings."""
         existing_kernel = self.get_conf("settings", {})
@@ -205,6 +217,32 @@ def load_connection_settings(self):
         except Exception:
             pass
 
+    def _validate_connection_file(self):
+        cf_path = osp.dirname(self.cf.text())
+        cf_filename = osp.basename(self.cf.text())
+        try:
+            if not cf_filename.endswith(".json"):
+                cf_filename += ".json"
+            connection_file = find_connection_file(
+                filename=cf_filename, path=cf_path
+            )
+        except OSError:
+            connection_file = None
+
+        if connection_file is None:
+            QMessageBox.error(
+                self,
+                _('Error'),
+                _(
+                    "The connection file you passed doesn't exist or can't be "
+                    "found by Spyder."
+                ),
+                QMessageBox.Ok
+            )
+        else:
+            self.accept()
+
+
     def save_connection_settings(self):
         """Save user's kernel connection settings."""
 
diff --git a/spyder/plugins/ipythonconsole/widgets/tests/test_kernelconnect.py b/spyder/plugins/ipythonconsole/widgets/tests/test_kernelconnect.py
index dea1641bb93..ea371abcef0 100644
--- a/spyder/plugins/ipythonconsole/widgets/tests/test_kernelconnect.py
+++ b/spyder/plugins/ipythonconsole/widgets/tests/test_kernelconnect.py
@@ -12,7 +12,8 @@
 import sys
 import pytest
 from qtpy.QtCore import Qt
-from qtpy.QtWidgets import QDialogButtonBox
+from qtpy.QtWidgets import QDialogButtonBox, QMessageBox
+from unittest.mock import patch
 
 # Local imports
 from spyder.config.base import running_in_ci
@@ -117,9 +118,10 @@ def test_connection_dialog_remembers_input_with_ssh_passphrase(
     dlg = connection_dialog_factory.submit_filled_dialog(use_keyfile=True,
                                                          save_settings=True)
 
-    # Press ok and save connection settings
-    qtbot.mouseClick(dlg.accept_btns.button(QDialogButtonBox.Ok),
-                     Qt.LeftButton)
+    with patch.object(QMessageBox, 'warning', return_value=None):
+        # Press ok and save connection settings
+        qtbot.mouseClick(dlg.accept_btns.button(QDialogButtonBox.Ok),
+                         Qt.LeftButton)
 
     # create new dialog and check fields
     new_dlg = connection_dialog_factory.get_default_dialog()
@@ -144,9 +146,10 @@ def test_connection_dialog_doesnt_remember_input_with_ssh_passphrase(
     dlg = connection_dialog_factory.submit_filled_dialog(use_keyfile=True,
                                                          save_settings=False)
 
-    # Press ok and save connection settings
-    qtbot.mouseClick(dlg.accept_btns.button(QDialogButtonBox.Ok),
-                     Qt.LeftButton)
+    with patch.object(QMessageBox, 'warning', return_value=None):
+        # Press ok and save connection settings
+        qtbot.mouseClick(dlg.accept_btns.button(QDialogButtonBox.Ok),
+                         Qt.LeftButton)
 
     # create new dialog and check fields
     new_dlg = connection_dialog_factory.get_default_dialog()
@@ -170,9 +173,10 @@ def test_connection_dialog_remembers_input_with_password(
     dlg = connection_dialog_factory.submit_filled_dialog(use_keyfile=False,
                                                          save_settings=True)
 
-    # Press ok and save connection settings
-    qtbot.mouseClick(dlg.accept_btns.button(QDialogButtonBox.Ok),
-                     Qt.LeftButton)
+    with patch.object(QMessageBox, 'warning', return_value=None):
+        # Press ok and save connection settings
+        qtbot.mouseClick(dlg.accept_btns.button(QDialogButtonBox.Ok),
+                         Qt.LeftButton)
 
     # create new dialog and check fields
     new_dlg = connection_dialog_factory.get_default_dialog()
@@ -196,9 +200,10 @@ def test_connection_dialog_doesnt_remember_input_with_password(
     dlg = connection_dialog_factory.submit_filled_dialog(use_keyfile=False,
                                                          save_settings=False)
 
-    # Press ok and save connection settings
-    qtbot.mouseClick(dlg.accept_btns.button(QDialogButtonBox.Ok),
-                     Qt.LeftButton)
+    with patch.object(QMessageBox, 'warning', return_value=None):
+        # Press ok and save connection settings
+        qtbot.mouseClick(dlg.accept_btns.button(QDialogButtonBox.Ok),
+                         Qt.LeftButton)
 
     # create new dialog and check fields
     new_dlg = connection_dialog_factory.get_default_dialog()


Code review comments:
diff_hunk: @@ -205,6 +217,32 @@ def load_connection_settings(self):
         except Exception:
             pass
 
+    def _validate_connection_file(self):
+        cf_path = osp.dirname(self.cf.text())
+        cf_filename = osp.basename(self.cf.text())
+        try:
+            if not cf_filename.endswith(".json"):
+                cf_filename += ".json"
+            connection_file = find_connection_file(
+                filename=cf_filename, path=cf_path
+            )
+        except OSError:
+            connection_file = None
+
+        if connection_file is None:
+            QMessageBox.error(
path: spyder/plugins/ipythonconsole/widgets/kernelconnect.py
text: @user1:
```suggestion
            QMessageBox.critical(
```