Page MenuHome

Blender is unable to generate a complete error message when there is bad indentation in python code
Open, Confirmed, MediumPublic

Description

Blender Version
Broken: 2.80 RC2 (Win 64)
Worked: 2.79b (Win 64)

Short description of error
Blender's built in Python interpreter is not able to load part of the error message when an IndentationError is thrown in 2.80.

Exact steps for others to reproduce the error

  1. Open Blender from a console,
  2. Paste the script below into Blender's text editor and run it
import bpy

def foo():
print("hello")

foo()

Console output from 2.79

location: <unknown location>:-1
Error:   File "\Text", line 4
    print("hello")
        ^
IndentationError: expected an indented block

Console output from 2.80

AttributeError: 'IndentationError' object has no attribute 'msg'
Error: Python script failed, check the message in the system console

Details

Type
Bug

Event Timeline

nBurn (nBurn) added a project: Python.
nBurn (nBurn) renamed this task from bpy is not including line number when there is bad indentation to bpy is not including a line number when there is bad indentation.
nBurn (nBurn) renamed this task from bpy is not including a line number when there is bad indentation to Blender is unable to generate a complete error message when there is bad indentation in python code.

I don't know if bpy_traceback.c changed, or if python was updated since 2.79b.

In bpy_traceback.c, void python_script_error_jump(...), there is this line:

if (exception && PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {

What is weird is that an Indentation error is considered as a Syntax error.

I'm wondering if instead we should write:

if (exception && PyErr_GivenExceptionMatches(exception, PyExc_NotImplementedError)) {

In this case, the errors messages seems to be displayed correctly.

But this needs to be reviewed by @Campbell Barton (campbellbarton) . Furthermore, this doesn't solve the issue to not have the line number in the error if we have a "NonImplemented" error I guess.

python C 3 exception handling code: https://docs.python.org/3/c-api/exceptions.html

Germano Cavalcante (mano-wii) triaged this task as Confirmed, Medium priority.

It seems that this can even result in crash.