fixed #4169562367585 #4169562367589 better error handling