diff --git a/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml b/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml new file mode 100644 index 000000000..0188ff0b4 --- /dev/null +++ b/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml @@ -0,0 +1,5 @@ +minor_changes: + - zos_copy - Adds a better error message that gives user a + hint that copy issue can be due to a GDS part of ``src`` GDG is + being used by another process. + (https://github.com/ansible-collections/ibm_zos_core/pull/2220) \ No newline at end of file diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index 0a9c0d090..0d2ac0213 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -1205,9 +1205,23 @@ def copy_to_gdg(self, src, dest): # If identical_gdg_copy is False, use the default next generation dest_gen_name = f"{dest}(+1)" # Perform the copy operation - rc = datasets.copy(gds.name, dest_gen_name, **copy_args) - if rc != 0: - success = False + + try: + result = datasets.copy(gds.name, dest_gen_name, **copy_args) + rc = result.rc if hasattr(result, 'rc') else result + if rc != 0: + success = False + except zoau_exceptions.ZOAUException as e: + stderr = getattr(e.response, 'stderr_response', str(e)) + if "BGYSC0514E" in stderr : + raise GenerationDataGroupCreateError( + msg=( + "BGYSC0514E An error occurred while attempting to define the file." + " This might be because the GDS part of the src GDG is being used by another process." + ) + ) from e + else: + raise GenerationDataGroupCreateError(msg=f"GDG creation failed. Raw error: {stderr}") from e return success def _copy_tree(self, entries, src, dest, dirs_exist_ok=False): @@ -4343,5 +4357,12 @@ def __init__( super().__init__(msg) +class GenerationDataGroupCreateError(Exception): + def __init__(self, msg): + """Error during copy of a Generation Data Group.""" + self.msg = msg + super().__init__(self.msg) + + if __name__ == "__main__": main()