Add error propagation layer. Patch #5916, slightly revised.