Skip to content

Commit 8978cff

Browse files
committed
Add new ErrorGroup exception
1 parent 470b7bd commit 8978cff

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Lib/shutil.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
class Error(OSError):
6868
pass
6969

70+
class ErrorGroup(Error):
71+
"""Used when gathering multiple exceptions"""
72+
7073
class SameFileError(Error):
7174
"""Raised when source and destination are the same file."""
7275

@@ -531,10 +534,10 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function,
531534
else:
532535
# Can raise SpecialFileError or SameFileError
533536
copy_function(srcobj, dstname)
534-
except SameFileError as err:
535-
errors.append((srcname, dstname, str(err)))
537+
except ErrorGroup as err_group:
538+
errors.extend(err_group.args[0])
536539
except Error as err:
537-
errors.extend(err.args[0])
540+
errors.append((srcname, dstname, str(err)))
538541
except OSError as why:
539542
errors.append((srcname, dstname, str(why)))
540543
try:
@@ -544,7 +547,7 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function,
544547
if getattr(why, 'winerror', None) is None:
545548
errors.append((src, dst, str(why)))
546549
if errors:
547-
raise Error(errors)
550+
raise ErrorGroup(errors)
548551
return dst
549552

550553
def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,

0 commit comments

Comments
 (0)