Open
Description
So when an error occurs, we can unroll the pipe properly in the backtrace. I'm going to hardcode logic based on 1.5 internals in rlang for the time being so we should coordinate before the next release of magrittr.
For illustration, let's say that T()
below throws and a backtrace is recorded:
F(NA) %>% F() %>% T() %>% F() %>% F()
We want to unroll the pipe but not the last two steps as they were not evaluated yet:
Full:
█
└─F(NA) %>% F() %>% T() %>% F() %>% F()
├─withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
└─eval(quote(`_fseq`(`_lhs`)), env, env)
└─eval(quote(`_fseq`(`_lhs`)), env, env)
└─`_fseq`(`_lhs`)
└─freduce(value, `_function_list`)
└─function_list[[i]](value)
└─T(.)
Collapsed:
█
└─[ F(NA) %>% F() %>% T() %>% F() %>% F() ] ... +6
└─T(.)
Trail:
─F(NA)
─F(.)
─T(.)
Useful pieces of information:
- How many pipe calls have already been evaluated
- Frame index of the evaluation loop so that it's easy to collapse irrelevant sections of the call tree.
- Caller environment
Probably best to record it in the very first frame, the one whose call is x %>% y %>% z
.