Fix an error handling bug