Okay. It really sounds to me like an ErrorContextCallback would help you here. I don't see a need to complicate statatt_build_stavalues(), but my intuition can also be wrong.
Sigh. errsave_finish() only calls errfinish() on elevel >= ERROR, and that's where the context stack is walked. The failed work in progress is attached too, mostly as a cautionary tale.
v5-0001 includes tests for null expressions on the leading and trailing end.