Tracing Nested Function Calls
A nested call has its own parameter bindings and returns a result to a specific pending operation in its caller.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Use one row per entry and return
For square(add(2, 5)), the inner call must return seven before the outer function can square it. The runtime creates the relevant invocation context for each. Evaluation order explains the nested argument sequence.
Identify the failing input
Suppose add is replaced with a parser and raises on an invalid field. The outer square never begins. Include the actual parser argument in a trace and read the call chain from the traceback to locate its source.[1][2]
Record who receives each return value
Suppose label(3) first calls double(3), which returns six, then calls format_id(6), which returns "ID-06". A trace should show the label frame waiting while each dependency runs. Its parameter can still be three even when a dependency receives six. Write the return destination next to each result to avoid reading an intermediate integer as the final output. See function parameters and arguments.
Trace the failure path with the same frames
If double raises while called by label, formatting never begins unless a surrounding handler decides how to continue. A record of calls shows which routines executed. A traceback additionally shows where the exception escaped. Test a helper that returns a usable value and one that raises, then examine whether an outer layer should handle the error or preserve it. See reading Python tracebacks for how the frames appear.