Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-UTF-8 code - Traceback not pointing to line with error #969

Closed
excubo-jg opened this issue Jul 1, 2022 · 1 comment
Closed

Non-UTF-8 code - Traceback not pointing to line with error #969

excubo-jg opened this issue Jul 1, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@excubo-jg
Copy link

excubo-jg commented Jul 1, 2022

Steps to Reproduce

  1. Create .py file:
    from torch.utils.tensorboard import SummaryWriter

random_seed = 1 # ç

  1. "Open in Terminal" and execute file gives this error message:
    SyntaxError: Non-UTF-8 code starting with '\xe7' in file C:\Users\Admin\source\repos\PythonTestApplication1\PythonApplication1\PythonApplication1.py on line 4, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details

  2. "Start" debugger in VS creates these error messages which do point to Anaconda but not to the cause of the problem:

Traceback (most recent call last):
  File "_pydevd_bundle/pydevd_cython.pyx", line 532, in _pydevd_bundle.pydevd_cython.PyDBFrame._handle_exception
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\linecache.py", line 30, in getline
    lines = getlines(filename, module_globals)
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\linecache.py", line 46, in getlines
    return updatecache(filename, module_globals)
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\linecache.py", line 137, in updatecache
    lines = fp.readlines()
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 71: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 444, in main
    run()
  File "c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Admin\source\repos\PythonTestApplication1\PythonApplication1\PythonApplication1.py", line 1, in <module>
  File "_pydevd_bundle/pydevd_cython.pyx", line 1366, in _pydevd_bundle.pydevd_cython.SafeCallWrapper.__call__
  File "_pydevd_bundle/pydevd_cython.pyx", line 662, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch
  File "_pydevd_bundle/pydevd_cython.pyx", line 836, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch
  File "_pydevd_bundle/pydevd_cython.pyx", line 452, in _pydevd_bundle.pydevd_cython.PyDBFrame.handle_user_exception
  File "_pydevd_bundle/pydevd_cython.pyx", line 535, in _pydevd_bundle.pydevd_cython.PyDBFrame._handle_exception
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\linecache.py", line 30, in getline
    lines = getlines(filename, module_globals)
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\linecache.py", line 46, in getlines
    return updatecache(filename, module_globals)
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\linecache.py", line 137, in updatecache
    lines = fp.readlines()
  File "C:\Users\Admin\anaconda3\envs\dominion\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 71: invalid continuation byte
The thread 'MainThread' (0x1) has exited with code 0 (0x0).
The program 'python.exe' has exited with code 1 (0x1).

Expected behavior
Same error message as if executed from Terminal

Configuration information (If you are providing a diagnostics file (see below), skip this section)
VS Version: Version 17.3.0 Preview 2.0
PTVS version: 17.0.22147.1
Python version: Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32

@int19h int19h transferred this issue from microsoft/PTVS Jul 1, 2022
@int19h int19h added bug Something isn't working and removed needs triage labels Jul 6, 2022
@int19h
Copy link
Contributor

int19h commented Jul 6, 2022

@fabioz Looks like the code path that uses linecache to retrieve source needs to handle this exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants