@@ -79,7 +79,18 @@ def _gcs_list_dir(gcs_path):
79
79
"""Recursively returns a list of contents for a directory on GCS."""
80
80
args = [GSUTIL , "ls" , "-r" , gcs_path ]
81
81
logging .info ("Listing GCS contents: %s" , " " .join (args ))
82
- result = subprocess .run (args = args , capture_output = True , text = True , check = True )
82
+ try :
83
+ result = subprocess .run (args = args , capture_output = True , text = True , check = True )
84
+ except subprocess .CalledProcessError as e :
85
+ # It's possible to have a CalledProcessError but still have gotten a file list.
86
+ # Check the stdout to see if we got lines that look GCS file paths, and ignore
87
+ # the error if so.
88
+ output = e .output .splitlines ()
89
+ if len (output ) > 1 and gcs_path in output [0 ]:
90
+ return output
91
+ else :
92
+ print ("Error: %s" % e .stderr )
93
+ raise e
83
94
return result .stdout .splitlines ()
84
95
85
96
@@ -88,7 +99,11 @@ def _gcs_read_file(gcs_path):
88
99
"""Extracts the contents of a file on GCS."""
89
100
args = [GSUTIL , "cat" , gcs_path ]
90
101
logging .info ("Reading GCS file: %s" , " " .join (args ))
91
- result = subprocess .run (args = args , capture_output = True , text = True , check = True )
102
+ try :
103
+ result = subprocess .run (args = args , capture_output = True , text = True , check = True )
104
+ except subprocess .CalledProcessError as e :
105
+ print ("Error: %s" % e .stderr )
106
+ raise e
92
107
return result .stdout
93
108
94
109
0 commit comments