128

How long before a traceback stops looking like a wall of noise Concepts

Three months of evenings. When something breaks I still feel a small drop in my stomach, scroll to the bottom, read the last line and start guessing. People around me seem to read the whole thing and go straight to the problem. Is there a trick to this or is it purely repetition?

8 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @goroutine_gil · 2w ago · 3 replies

    Mostly repetition, but there is a reading order that speeds it up enormously.

    • Read the last line first. That is the exception type and message, and it tells you what went wrong.
    • Then read upwards through the stack until you reach the last file that is yours rather than a library. That is where it went wrong.
    • Everything above that is the path that got you there, and is only interesting when the answer is not obvious at step two.

    So: what, then where, then how. Most people read top to bottom, drown in library frames and give up. Flip the order and tracebacks become the most useful output Python produces.

    The stomach drop fades around the point where you have met the same six exception types enough times to recognise them by shape.

    118
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @etcd_eli · 2w ago

      It is one of those things everybody learns by accident and nobody teaches.

      40
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @patch_pocket_pia · 2w ago

      Bottom first, then upwards to my own file. I have genuinely never been told that.

      34
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @etcd_eli · 2w ago · 3 replies

    Learn what the common ones mean before you meet them at 1am. TypeError is usually the wrong kind of thing, AttributeError is usually None where you expected an object, KeyError means the key is not there, IndexError means the list is shorter than you think. Those four cover most beginner evenings.

    66
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @etcd_eli · 2w ago

      It usually means a function returned nothing where you expected an object. Work backwards to whatever produced that variable rather than staring at the line that blew up.

      26
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @patch_pocket_pia · 2w ago

      AttributeError on None is the one I keep hitting and never understood as a category.

      20
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @airgap_amir · 2w ago

    Three months in and you read the last line and form a hypothesis. That is the process, it just gets faster.

    40
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @proof_pilar · 2w ago

    Keep a file with each error message and a one line note about what caused it. After thirty entries you have your own index and you stop searching for them.

    22
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report