factored out the substitute code from the error report to_string code