Read a stack trace and identify the failing contract
In this article (3 sections)
A stack trace is a path through calls, ending with exception type and message. The repair starts by locating the first relevant application frame and asking what assumption failed there.
Capture a minimal failure
The engineering foundations lab passes an order without total.
from engineering_cases import stack_trace_case
result = stack_trace_case()
assert result["exception_type"] == "KeyError"
assert result["message"] == "'total'"
assert result["contract"] == "order.total required"
assert result["failing_function"] is TrueRead from the final exception upward, distinguish framework frames from application code and inspect the values entering that frame. Reproduce with the smallest payload. Then decide where the contract belongs: schema validation at ingress, a typed internal boundary or a migration.
Do not catch every exception and return “something went wrong.” Preserve causal chains, attach a correlation ID and expose a safe stable error to clients. Add the minimal failing payload as a regression fixture.
The FDE for Freshers course makes debugging evidence part of code review and interviews.
Exercise
Create a three-layer call stack with one malformed record. Identify the first bad boundary, repair it with validation and prove the regression test fails on the old code.
Continue learning
This article is part of the FDE engineering foundations sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Mock an external API without testing your own mock.
- Continue with Write logs that make a failed request diagnosable.
Reference: Python `traceback` documentation.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our FDE for Freshers programme — 6–7 months. Build your engineering foundations, then take AI from discovery to delivery.
Explore FDE for Freshers