@@ -79,7 +79,18 @@ def _gcs_list_dir(gcs_path):
7979 """Recursively returns a list of contents for a directory on GCS."""
8080 args = [GSUTIL , "ls" , "-r" , gcs_path ]
8181 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
8394 return result .stdout .splitlines ()
8495
8596
@@ -88,7 +99,11 @@ def _gcs_read_file(gcs_path):
8899 """Extracts the contents of a file on GCS."""
89100 args = [GSUTIL , "cat" , gcs_path ]
90101 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
92107 return result .stdout
93108
94109
0 commit comments