fix some error handles for unstable environment