@@ -144,8 +144,14 @@ def collect_diffs(self, start_id: int, max_size: Optional[int] = None,
144144 contains the MergeInputReader with the data and `newest` is a
145145 sequence id of the most recent diff available.
146146
147- Returns None if there was an error during download or no new
148- data was available.
147+ Returns None if there was no new data was available.
148+
149+ If there is an error during the download, then the function will
150+ simply return the already downloaded data. If the reported
151+ error is a client error (HTTP 4xx) and happens during the download
152+ of the first diff, then a ::request.HTTPError:: is raised: this
153+ condition is likely to be permanent and the caller should not
154+ simply retry without investigating the cause.
149155 """
150156 # must not read data newer than the published sequence id
151157 # or we might end up reading partial data
@@ -168,8 +174,19 @@ def collect_diffs(self, start_id: int, max_size: Optional[int] = None,
168174 and current_id <= newest .sequence :
169175 try :
170176 diffdata = self .get_diff_block (current_id )
171- except : # noqa: E722
172- LOG .error ("Error during diff download. Bailing out." )
177+ except requests .RequestException as ex :
178+ if start_id == current_id \
179+ and ex .response is not None \
180+ and (ex .response .status_code % 100 == 4 ):
181+ # If server directly responds with a client error,
182+ # reraise the exception to signal a potentially permanent
183+ # error.
184+ LOG .error ("Permanent server error: %s" , ex .response )
185+ raise ex
186+ # In all other cases, process whatever diffs we have and
187+ # encourage a retry.
188+ LOG .error ("Error during diff download: %s" , ex )
189+ LOG .error ("Bailing out." )
173190 diffdata = ''
174191 if len (diffdata ) == 0 :
175192 if start_id == current_id :
0 commit comments