Get the latest tech news
Stack Traces Are Underrated
I Love Stack Traces When something goes wrong in a program, many languages will spit out a stack trace with lots of useful information. Here's an example from one of my Python programs: Traceback (most recent call last): File "/home/piku/.piku/envs/wikdict/lib/python3.11/site-packages/flask/app.py", line 1511, in wsgi_app response = self.full_dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/piku/.piku/envs/wikdict/lib/python3.11/site-packages/flask/app.py", line 919, in full_dispatch_request rv = self.handle_user_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/piku/.piku/envs/wikdict/lib/python3.11/site-packages/flask/app.py", line 917, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/piku/.piku/envs/wikdict/lib/python3.11/site-packages/flask/app.py", line 902, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/piku/.piku/apps/wikdict/wikdict_web/lookup.py", line 119, in lookup if r := get_combined_result(lang, other_lang, query): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/piku/.piku/apps/wikdict/wikdict_web/lookup.py", line 91, in get_combined_result conn = get_conn(lang + "-" + other_lang) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/piku/.piku/apps/wikdict/wikdict_web/base.py", line 103, in get_conn raise sqlite3.OperationalError( sqlite3.OperationalError: Database file "/home/piku/.piku/data/wikdict/dict/en-ko.sqlite3" does not exist Beautiful! In addition to the error, I immediately see the line that caused the error, the full call stack and I have the file paths and line numbers at hand to quickly jump to each of the locations.
Many people dislike exceptions since they break the usual control flow and make it easy to skip proper error handling. If you have an HTTP call between your functions, you will have to put a large amount of work into your tooling to get something nearly as useful and consistent as Python's default stack traces. Collecting the traces can cost some performance, but that is a small price to pay for the advantages and could even be turned off in production builds.
Or read this on Hacker News