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.

Cant see traceback

See original GitHub issue
class FooConsumer(SyncConsumer):
    def connect(self):
        assert False

    ...

produces

WebSocket HANDSHAKING /foo/ [127.0.0.1:00000]
WebSocket DISCONNECT /foo/ [127.0.0.1:00000]

With no traceback

python==3.6.8
django==1.11.16
channels==2.2.0
daphne==2.1.0
channels-redis==2.1.1
asgi-redis==1.4.3
asgiref==2.2.0

macOS Mojave 10.14.1

When I try to reproduce this with a minimal setup, it gives traceback

Exception inside application: 
  File "/path/to/django_sandbox/venv/lib/python3.6/site-packages/channels/sessions.py", line 183, in __call__
 ... 
  File "/path/to/django_sandbox/foo/consumers.py", line 7, in connect
    assert False

as expected.

Adding a print

logger.error("Exception inside application: %s", exception_output)
print(exception_output)

inside daphne.server.Server.application_checker allows me to see the output, so it seems daphne swallows the errors somehow.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:23 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Ivo-Donchevcommented, Nov 1, 2019

Hey guys 🙂 ,

I think I found what’s the issue 🔥 🎉

So, what I did:

  1. I created a super basic django project (as @carltongibson suggested) and start reproducing the bug - https://github.com/HackSoftware/django-channels-playground
  2. I couldn’t reproduce in this clean state ❌
  3. So I reproduce it in the project we first hit it and started slicing things from the code
  4. I turned out that django-debug-toolbar was causing the issue in our case 😦 So it’s not a channels issue

I searched in the other issues and found this - https://github.com/django/channels/issues/1193 (there’s a suggested quickfix there)

I started debugging the django-debug-toolbar code to find the root of the problem and turned out that this class is causing it - https://github.com/jazzband/django-debug-toolbar/blob/87eb27ffb2d0aea60b8b139360ece4d9fc91b47e/debug_toolbar/utils.py#L222

It’s used by a code hooked to the python logging module and collects only the logs from the current thread (which channels is not part from) 😞

https://github.com/django/channels/issues/1340#issuecomment-539957522 - this was solving the problem because the print is forcing a message to the standart output rather than using the python logging module

Hope this will help someone ^

2reactions
Wrufeshcommented, Jul 9, 2020

Same here

backend:

WebSocket HANDSHAKING /webrtc/ [127.0.0.1:38882]
WebSocket DISCONNECT /webrtc/ [127.0.0.1:38882]
WebSocket HANDSHAKING /webrtc/ [127.0.0.1:39086]
WebSocket DISCONNECT /webrtc/ [127.0.0.1:39086]
WebSocket HANDSHAKING /webrtc/ [127.0.0.1:39114]
WebSocket DISCONNECT /webrtc/ [127.0.0.1:39114]
WebSocket HANDSHAKING /webrtc/ [127.0.0.1:39208]
WebSocket DISCONNECT /webrtc/ [127.0.0.1:39208]

frontend:

WebSocket connection to 'ws://localhost:8000/webrtc/' failed: Error during WebSocket handshake: Unexpected response code: 500
Read more comments on GitHub >

github_iconTop Results From Across the Web

PyCharm 2019.2 not showing Traceback on Exception
It throws an error, you pause. Traceback in the console is literally the last thing handler does. But you pause it before handler...
Read more >
Understanding the Python Traceback
Python prints a traceback when an exception is raised in your code. The traceback output can be a bit overwhelming if you're seeing...
Read more >
How to read a traceback in Python
When Python encounters an error in your code, it will print out a traceback. Let's talk about how to use tracebacks to fix...
Read more >
traceback — Print or retrieve a stack traceback — Python 3.11 ...
Source code: Lib/traceback.py This module provides a standard interface to extract, format and print stack traces of Python programs.
Read more >
A simple way to show stack trace on error in R - Kun Ren
Unfortunately, it is not quite helpful since we don't see anything like x + y if we don't read the source code of...
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