Impossible to get errors from sys.stderr when script executed from the Text Editor area #115090

Closed
opened 2023-11-18 13:03:33 +01:00 by Nikita Akimov · 3 comments

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 680/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 466.27

Blender Version
Broken: version: 4.0.1, branch: blender-v4.0-release, commit date: 2023-11-16 16:40, hash: d0dd92834a08
Caused by 6a0f98aeef

Short description of error
It is impossible to get errors from sys.stderr when script executed from the Text Editor area in Blender 4.0.1.

Exact steps for others to reproduce the error
The simple code example:

import sys
import bpy

def err_hook(exctype, value, traceback):
    # write err to file hook
    with open(bpy.path.abspath("//") + "err_to_file_test_4_0.txt", 'w') as file:
        file.write('execpthook_test 4.0')
    
sys.excepthook = err_hook

# write error to file
print(1/0)

This code correctly works with Blender 3.6 and less. When exception occurs - test debug file successfully created.
But in Blender 4.0.1 this code does nothing. File doesn't create.

This makes it impossible to debug and log errors when developing and debugging Blender add-ons.

Attached two files with the same code. One from Blender 3.6 - it works as expected, the second from Blender 4.0.1 - it doesn't create debug log-file.

**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce GTX 680/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 466.27 **Blender Version** Broken: version: 4.0.1, branch: blender-v4.0-release, commit date: 2023-11-16 16:40, hash: `d0dd92834a08` Caused by 6a0f98aeef **Short description of error** It is impossible to get errors from sys.stderr when script executed from the Text Editor area in Blender 4.0.1. **Exact steps for others to reproduce the error** The simple code example: ```Py import sys import bpy def err_hook(exctype, value, traceback): # write err to file hook with open(bpy.path.abspath("//") + "err_to_file_test_4_0.txt", 'w') as file: file.write('execpthook_test 4.0') sys.excepthook = err_hook # write error to file print(1/0) ``` This code correctly works with Blender 3.6 and less. When exception occurs - test debug file successfully created. But in Blender 4.0.1 this code does nothing. File doesn't create. This makes it impossible to debug and log errors when developing and debugging Blender add-ons. Attached two files with the same code. One from Blender 3.6 - it works as expected, the second from Blender 4.0.1 - it doesn't create debug log-file.
Nikita Akimov added the
Type
Report
Priority
Normal
Status
Needs Triage
labels 2023-11-18 13:03:33 +01:00

Can confirm. Will have to bisect to see what has introduced this change.

Can confirm. Will have to bisect to see what has introduced this change.
Richard Antalik added
Module
Python API
Status
Confirmed
and removed
Status
Needs Triage
labels 2023-11-23 05:53:53 +01:00

Caused by 6a0f98aeef, CC @ideasman42

Caused by 6a0f98aeefcba807918c9518c73f8362c406d315, CC @ideasman42

I wasn't aware script authors depended on PyErr_Print to call sys.excepthook so that moving to PyErr_Display would cause a problem.

Looking into this further, I don't think the behavior in 3.6 was correct either.

  • v3.6

    • Temporarily overrode sys.stderr
    • Call PyErr_Print().
    • PyErr_Print detected sys.excepthook which it called instead but
      didn't necessarily print to the sys.stderr,
      causing an empty exception.
  • 4.0

    • Temporarily overrode sys.stderr
    • Call PyErr_Display(...) as it accepts the exception arguments and always prints the message.
    • sys.excepthook wasn't called as it was in 3.6 but the message.

Preparing a fix that calls sys.excepthook without it suppressing the message from PyC_ExceptionBuffer.

I wasn't aware script authors depended on `PyErr_Print` to call `sys.excepthook` so that moving to `PyErr_Display` would cause a problem. Looking into this further, I don't think the behavior in 3.6 was correct either. - v3.6 - Temporarily overrode `sys.stderr` - Call `PyErr_Print()`. - PyErr_Print detected `sys.excepthook` which it called instead but didn't necessarily print to the `sys.stderr`, causing an empty exception. - 4.0 - Temporarily overrode `sys.stderr` - Call `PyErr_Display(...)` as it accepts the exception arguments and always prints the message. - `sys.excepthook` wasn't called as it was in 3.6 but the message. ---- Preparing a fix that calls `sys.excepthook` without it suppressing the message from `PyC_ExceptionBuffer`.
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-11-28 03:37:15 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#115090
No description provided.