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.

Gracefully handle exception being "(None, None, None)"

See original GitHub issue

Hi!

The built-in traceback module handles (None, None, None) tuple (returned if sys.exc_info() is called outside the context of an exception) without raising an error:

import traceback

traceback.print_exception(None, None, None)
# 'NoneType: None'

Using stackprinter, however:

import stackprinter

stackprinter.format((None, None, None))
# ValueError: Can't format (None, None, None). Expected an exception instance, sys.exc_info() tuple,a frame or a thread object.

You may argue that formatting such exception is pretty useless… You’re right. 😄

Still, in my situation it happens that the exception tuple looks more like (TypeError, None, None) (I’ll save you the details, but it happens if the error value can’t be serialized, then it is replaced by None by default). In such case, it would be nice to format the error like TypeError: None for example instead of raising a ValueError. That would be useful so that user could format any exception-tuple without having to check for edge cases like that.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JulianOrteilcommented, Nov 4, 2020

Saw this, thank you. Already updated my installation 👍

0reactions
ckndcommented, Nov 4, 2020

cc @JulianOrteil ☝️

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle errors with grace: failing silently is not an ...
It's fine if you care about different kinds of errors which need to be handled differently, but do your users a favor and...
Read more >
Why is the error handling not working for None input?
When you provide None as an input, it doesn't pass the if statement and falls through so nothing is returned and no exception...
Read more >
30. Errors and Exception Handling | Python Tutorial
An exception is an error that happens during the execution of a program. Exceptions are known to non-programmers as instances that do not...
Read more >
Clean Code and the Art of Exception Handling
Exception Handling: It's a Good Thing · Always create your own ApplicationError hierarchy · Never rescue Exception · Never rescue more exceptions than...
Read more >
9 Best Practices to Handle Java Exceptions
Handling Java exceptions isn't easy, especially for beginners. Read this post to understand exceptions and best practices for using them.
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