Repository: spyder-ide/spyder

Issue:
Debugger raises encoding error
## Problem Description
I have been using Spyder 5 for a few weeks without any major issues then today the debugger stopped working and raises an encoding error on every script I have. The scripts execute fine when I run them the issue only happens when I debug. I have tried uninstalling and reinstalling anaconda and the problem persists. In the new anaconda installation I have the same problem with spyder version 4. I also tried using pycharm and that was able to run and debug without issue.


### What steps reproduce the problem?

Not sure how this can be reproduced.

### What is the expected output? What do you see instead?

Debugger to work as normal.

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

Exception in comms call set_breakpoints:
  File "C:\Users\seano\anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(
  File "C:\Users\seano\anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](
  File "C:\Users\seano\anaconda3\lib\site-packages\spyder_kernels\console\kernel.py", line 284, in set_spyder_breakpoints
    self._pdb_obj.set_spyder_breakpoints(breakpoints)
  File "C:\Users\seano\anaconda3\lib\site-packages\spyder_kernels\customize\spyderpdb.py", line 384, in set_spyder_breakpoints
    self.set_break(self.canonic(fname), linenumber,
  File "C:\Users\seano\anaconda3\lib\bdb.py", line 377, in set_break
    line = linecache.getline(filename, lineno)
  File "C:\Users\seano\anaconda3\lib\linecache.py", line 16, in getline
    lines = getlines(filename, module_globals)
  File "C:\Users\seano\anaconda3\lib\linecache.py", line 47, in getlines
    return updatecache(filename, module_globals)
  File "C:\Users\seano\anaconda3\lib\linecache.py", line 137, in updatecache
    lines = fp.readlines()
  File "C:\Users\seano\anaconda3\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcc in position 4116: invalid continuation byte


```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4/5
* Python version: 3.8/3.9
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: 

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```

# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.6.0 (OK)
diff_match_patch >=20181111    :  20200713 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.19.0 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
nbconvert >=4.0                :  6.0.7 (OK)
numpydoc >=0.6.0               :  1.1.0 (OK)
paramiko >=2.4.0               :  2.7.2 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.2 (OK)
pygments >=2.0                 :  2.7.2 (OK)
pylint >=1.0                   :  2.6.0 (OK)
pyls >=0.34.0;<1.0.0           :  0.35.1 (OK)
qdarkstyle >=2.8               :  2.8.1 (OK)
qtawesome >=0.5.7              :  1.0.1 (OK)
qtconsole >=4.6.0              :  4.7.7 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.4 (OK)
sphinx >=0.6.6                 :  3.2.1 (OK)
spyder_kernels >=1.9.4;<1.10.0 :  1.9.4 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  19.0.2 (OK)

# Optional:
cython >=0.21                  :  0.29.21 (OK)
matplotlib >=2.0.0             :  3.3.2 (OK)
numpy >=1.7                    :  1.19.2 (OK)
pandas >=0.13.1                :  1.1.3 (OK)
scipy >=0.17.0                 :  1.5.2 (OK)
sympy >=0.7.3                  :  1.6.2 (OK)

```



Discussion:
Hi @seanysull thanks for reporting this. Can you upload an example of a file that is not working for debugging? @impact27 can you take a look at this one? 
I tried the most basic file I could for testing by creating a new file in spyder and putting a=1, I have put an example below. I have switched back to Spyder 4 at the moment but will make another try to upgrade again soon and see if the issue still occurs.

```
# -*- coding: utf-8 -*-
"""
Created on Wed May 12 15:03:04 2021

@author: seano
"""

a=1
```

You have a corrupted file with a breakpoint on it. You can remove it with: Debug > Clear breakpoints in all files


Resolving patch:
diff --git a/external-deps/spyder-kernels/spyder_kernels/customize/spyderpdb.py b/external-deps/spyder-kernels/spyder_kernels/customize/spyderpdb.py
--- a/external-deps/spyder-kernels/spyder_kernels/customize/spyderpdb.py
+++ b/external-deps/spyder-kernels/spyder_kernels/customize/spyderpdb.py
@@ -610,12 +610,15 @@ def set_spyder_breakpoints(self, breakpoints):
         bdb.Breakpoint.bplist = {}
         bdb.Breakpoint.bpbynumber = [None]
         # -----
-        i = 0
         for fname, data in list(breakpoints.items()):
             for linenumber, condition in data:
-                i += 1
-                self.set_break(self.canonic(fname), linenumber,
-                               cond=condition)
+                try:
+                    self.set_break(self.canonic(fname), linenumber,
+                                   cond=condition)
+                except ValueError:
+                    # Fixes spyder/issues/15546
+                    # The file is not readable
+                    pass
 
         # Jump to first breakpoint.
         # Fixes issue 2034


Test patch: