314
314
315
315
316
316
try :
317
- from zoautil_py import datasets , mvscmd , ztypes , gdgs
317
+ from zoautil_py import datasets , mvscmd , ztypes , gdgs , zoau_exceptions
318
318
except Exception :
319
319
datasets = ZOAUImportError (traceback .format_exc ())
320
320
mvscmd = ZOAUImportError (traceback .format_exc ())
321
321
ztypes = ZOAUImportError (traceback .format_exc ())
322
+ zoau_exceptions = ZOAUImportError (traceback .format_exc ())
322
323
323
324
324
325
class FetchHandler :
@@ -621,7 +622,7 @@ def _fetch_pdse(self, src, is_binary, temp_dir=None, encoding=None):
621
622
622
623
Raises
623
624
------
624
- fail_json
625
+ ZOSFetchError
625
626
Error copying partitioned dataset to USS.
626
627
fail_json
627
628
Error converting encoding of the member.
@@ -635,21 +636,23 @@ def _fetch_pdse(self, src, is_binary, temp_dir=None, encoding=None):
635
636
if is_binary :
636
637
copy_args ["options" ] = "-B"
637
638
638
- rc = datasets .copy (source = src , target = dir_path , ** copy_args )
639
+ try :
640
+ rc = datasets .copy (source = src , target = dir_path , ** copy_args )
639
641
640
- if rc != 0 :
642
+ except zoau_exceptions . ZOAUException as copy_exception :
641
643
rmtree (dir_path )
642
- self . _fail_json (
644
+ raise ZOSFetchError (
643
645
msg = (
644
646
"Error copying partitioned data set {0} to USS. Make sure it is"
645
647
" not empty" .format (src )
646
648
),
647
- stdout = "" ,
648
- stderr = "Error copying partitioned data set {0} to USS. Make sure it is not empty" ,
649
- stdout_lines = "" ,
650
- stderr_lines = "Error copying partitioned data set {0} to USS. Make sure it is not empty" .splitlines (),
651
- rc = rc ,
649
+ rc = copy_exception . response . rc ,
650
+ stdout = copy_exception . response . stdout_response ,
651
+ stderr = copy_exception . response . stderr_response ,
652
+ stdout_lines = copy_exception . response . stdout_response .splitlines (),
653
+ stderr_lines = copy_exception . response . stderr_response . splitlines () ,
652
654
)
655
+
653
656
if (not is_binary ) and encoding :
654
657
enc_utils = encode .EncodeUtils ()
655
658
from_code_set = encoding .get ("from" )
@@ -746,7 +749,7 @@ def _fetch_mvs_data(self, src, is_binary, temp_dir=None, file_override=None, enc
746
749
747
750
Raises
748
751
------
749
- fail_json
752
+ ZOSFetchError
750
753
Unable to copy to USS.
751
754
fail_json
752
755
Error converting encoding of the dataset.
@@ -767,18 +770,20 @@ def _fetch_mvs_data(self, src, is_binary, temp_dir=None, file_override=None, enc
767
770
if is_binary :
768
771
copy_args ["options" ] = "-B"
769
772
770
- rc = datasets .copy (source = src , target = file_path , ** copy_args )
773
+ try :
774
+ rc = datasets .copy (source = src , target = file_path , ** copy_args )
771
775
772
- if rc != 0 :
776
+ except zoau_exceptions . ZOAUException as copy_exception :
773
777
os .remove (file_path )
774
- self . _fail_json (
778
+ raise ZOSFetchError (
775
779
msg = "Unable to copy {0} to USS" .format (src ),
776
- stdout = "" ,
777
- stderr = "Unable to copy {0} to USS" . format ( src ) ,
778
- rc = rc ,
779
- stdout_lines = "" ,
780
- stderr_lines = "Unable to copy {0} to USS" . format ( src ),
780
+ rc = copy_exception . response . rc ,
781
+ stdout = copy_exception . response . stdout_response ,
782
+ stderr = copy_exception . response . stderr_response ,
783
+ stdout_lines = copy_exception . response . stdout_response . splitlines () ,
784
+ stderr_lines = copy_exception . response . stderr_response . splitlines ( ),
781
785
)
786
+
782
787
if (not is_binary ) and encoding :
783
788
enc_utils = encode .EncodeUtils ()
784
789
from_code_set = encoding .get ("from" )
@@ -1045,6 +1050,36 @@ def run_module():
1045
1050
module .exit_json (** res_args )
1046
1051
1047
1052
1053
+ class ZOSFetchError (Exception ):
1054
+ def __init__ (self , msg , rc = "" , stdout = "" , stderr = "" , stdout_lines = "" , stderr_lines = "" ):
1055
+ """Error in a copy operation.
1056
+
1057
+ Parameters
1058
+ ----------
1059
+ msg : str
1060
+ Human readable string describing the exception.
1061
+ rc : int
1062
+ Result code.
1063
+ stdout : str
1064
+ Standart output.
1065
+ stderr : str
1066
+ Standart error.
1067
+ stdout_lines : str
1068
+ Standart output divided in lines.
1069
+ stderr_lines : str
1070
+ Standart error divided in lines.
1071
+ """
1072
+ self .json_args = dict (
1073
+ msg = msg ,
1074
+ rc = rc ,
1075
+ stdout = stdout ,
1076
+ stderr = stderr ,
1077
+ stdout_lines = stdout_lines ,
1078
+ stderr_lines = stderr_lines ,
1079
+ )
1080
+ super ().__init__ (self .msg )
1081
+
1082
+
1048
1083
def main ():
1049
1084
run_module ()
1050
1085
0 commit comments