@@ -275,21 +275,8 @@ async def download_files_async(
275275 finally :
276276 os .remove (manifest_path )
277277
278- # 2. Validate manifest columns
279- if columns is None :
280- raise SynapseError (
281- "Manifest job succeeded but the downloaded CSV has no headers. "
282- "This is unexpected — the Synapse server may have returned an empty file."
283- )
284-
285- if _PATH_COLUMN in columns or _ERROR_COLUMN in columns :
286- raise SynapseError (
287- "The downloaded manifest CSV contains reserved column names 'path' or 'error'. "
288- "This is unexpected and may indicate a malformed manifest from the server, "
289- "or Synapse has added these columns."
290- )
291-
292- columns = list (columns ) + [_PATH_COLUMN , _ERROR_COLUMN ]
278+ # 2. Validate manifest columns and append result columns
279+ columns = DownloadList ._validate_and_extend_columns (columns )
293280
294281 # 3. Download each file in the manifest
295282 downloaded_files = await DownloadList ._download_all_rows (
@@ -342,6 +329,42 @@ def _read_manifest_rows(
342329 return None , []
343330 return list (columns ), rows
344331
332+ @staticmethod
333+ def _validate_and_extend_columns (
334+ columns : Optional [list [str ]],
335+ ) -> list [str ]:
336+ """Validate server manifest columns and append the result columns.
337+
338+ Ensures the server-generated manifest has headers and does not already
339+ contain the reserved "path" or "error" column names that are appended
340+ to the output manifest.
341+
342+ Arguments:
343+ columns: Column names from the server manifest, or None if the
344+ CSV had no headers.
345+
346+ Raises:
347+ SynapseError: If columns is None (empty manifest) or contains
348+ reserved column names.
349+
350+ Returns:
351+ The original columns with "path" and "error" appended.
352+ """
353+ if columns is None :
354+ raise SynapseError (
355+ "Manifest job succeeded but the downloaded CSV has no headers. "
356+ "This is unexpected — the Synapse server may have returned an empty file."
357+ )
358+
359+ if _PATH_COLUMN in columns or _ERROR_COLUMN in columns :
360+ raise SynapseError (
361+ "The downloaded manifest CSV contains reserved column names 'path' or 'error'. "
362+ "This is unexpected and may indicate a malformed manifest from the server, "
363+ "or Synapse has added these columns."
364+ )
365+
366+ return list (columns ) + [_PATH_COLUMN , _ERROR_COLUMN ]
367+
345368 @staticmethod
346369 def _write_result_manifest (
347370 path : str ,
0 commit comments