question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting syntax error instead of actual message of a thrown exception in Python

See original GitHub issue

Issue Type: Bug

I keep on getting very strange behavior when I execute lines of code in the the DEBUG CONSOLE: I get a syntax error, instead of the actual message of the exception. Here is a very simple example of a code snippet, that intentionally has an error in it:

import pandas as pd
# this is incorrect, as it should be "data = {'values': [1]}"
data = {'values': 1}
df = pd.DataFrame(data=data)

If I run this with the debugger, I get the expected ValueError in line 4 (“If using all scalar values, you must pass an index”). However, if I run this in the DEBUG CONSOLE, I get a syntax error instead of the message from the exception:

SyntaxError('invalid syntax', ('<string>', 1, 4, 'df = pd.DataFrame(data=data)'))

Any ideas? I get this all the time, not just for pandas. This behavior makes is really hard to debug code, because of the actual error message, I just get this SyntaxError.

Note, I also posted a question here, but to no avail: https://stackoverflow.com/questions/52861388/debug-console-throws-syntax-error-instead-of-showing-exception-message

Extension version: 2018.9.0 VS Code version: Code - Insiders 1.29.0-insider (9e83209ed59a22df3d593735d04cc963396bb89e, 2018-10-18T05:17:36.900Z) OS version: Windows_NT x64 10.0.17763

System Info
Item Value
CPUs Intel® Xeon® CPU E5-1620 v4 @ 3.50GHz (8 x 3492)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: unavailable_software
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 31.92GB (21.97GB free)
Process Argv
Screen Reader no
VM 0%

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcannoncommented, Oct 29, 2018

@jreynolds01 good catch, I’ll re-open the issue.

0reactions
DonJayamannecommented, Apr 4, 2019

Upstream issue has been resolved, hence closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

8. Errors and Exceptions — Python 3.11.1 documentation
If an exception occurs during execution of the try clause, the exception may be handled by an except clause. If the exception is...
Read more >
How to Throw Exceptions in Python
The syntax error exception occurs when the code does not conform to Python keywords, naming style, or programming structure. The interpreter ...
Read more >
Getting syntax error instead of actual message of a thrown ...
a=xyz() returns a SyntaxError ("invalid syntax") - I guess this is the issue here. In a Python terminal, a=1 works fine, as do...
Read more >
python exception message capturing
The syntax is no longer supported in python 3. Use the following instead. try: do_something() except BaseException as e: logger.error('Failed to do ...
Read more >
Python Exceptions: An Introduction
In Python, an error can be a syntax error or an exception. In this article, you will see what an exception is and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found