@@ -554,16 +554,23 @@ def pr_request_fn(gh):
554554
555555 # see also https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request,
556556 # in particular part about media types
557+ error_msg = None
557558 accept_diff = {'Accept' : 'application/vnd.github.diff' }
558- status , data = github_api_get_request (pr_request_fn , github_user = github_user , headers = accept_diff )
559- if status == HTTP_STATUS_OK :
560- # decode from bytes to text
561- diff_txt = data .decode ()
562- _log .debug ("Diff for PR #%s:\n %s" , pr , diff_txt )
563- write_file (diff_filepath , diff_txt )
564- else :
565- error_msg = f"Failed to download diff for { github_account } /{ github_repo } PR #{ pr } ! (HTTP status code: { status } )"
566- raise EasyBuildError (error_msg )
559+ try :
560+ status , data = github_api_get_request (pr_request_fn , github_user = github_user , headers = accept_diff )
561+ if status == HTTP_STATUS_OK :
562+ # decode from bytes to text
563+ diff_txt = data .decode ()
564+ _log .debug ("Diff for PR #%s:\n %s" , pr , diff_txt )
565+ write_file (diff_filepath , diff_txt )
566+ else :
567+ error_msg = f"HTTP status code: { status } "
568+ except HTTPError as err :
569+ error_msg = f"HTTP error: { err } "
570+
571+ if error_msg :
572+ error_msg = f"Failed to download diff for { github_account } /{ github_repo } PR #{ pr } ! ({ error_msg } )"
573+ raise EasyBuildError (error_msg , exit_code = EasyBuildExit .FAIL_GITHUB )
567574
568575 patched_files = det_patched_files (txt = diff_txt , omit_ab_prefix = True , github = True , filter_deleted = True )
569576 _log .debug ("List of patched files for PR #%s: %s" , pr , patched_files )
@@ -715,21 +722,27 @@ def fetch_files_from_commit(commit, files=None, path=None, github_account=None,
715722 def commit_request_fn (gh ):
716723 return gh .repos [github_account ][github_repo ].commits [commit ]
717724
718- # see also https://docs.github.com/en/rest/commits/commits#get-a-commit,
719- # in particular part about media types
720- accept_diff = {'Accept' : 'application/vnd.github.diff' }
721- status , data = github_api_get_request (commit_request_fn , github_user = github_user , headers = accept_diff )
722- if status == HTTP_STATUS_OK :
723- # decode from bytes to text
724- diff_txt = data .decode ()
725- _log .debug ("Diff for commit %s:\n %s" , commit , diff_txt )
725+ error_msg = None
726+ try :
727+ # see also https://docs.github.com/en/rest/commits/commits#get-a-commit,
728+ # in particular part about media types
729+ accept_diff = {'Accept' : 'application/vnd.github.diff' }
730+ status , data = github_api_get_request (commit_request_fn , github_user = github_user , headers = accept_diff )
731+ if status == HTTP_STATUS_OK :
732+ # decode from bytes to text
733+ diff_txt = data .decode ()
734+ _log .debug ("Diff for commit %s:\n %s" , commit , diff_txt )
735+ else :
736+ error_msg = f"HTTP status code: { status } "
737+ except HTTPError as err :
738+ error_msg = f"HTTP error: { err } "
726739
727- files = det_patched_files ( txt = diff_txt , omit_ab_prefix = True , github = True , filter_deleted = True )
728- _log . debug ( "List of patched files for commit %s: %s" , commit , files )
729- else :
730- error_msg = f"Failed to download diff for { github_account } / { github_repo } commit { commit } ! "
731- error_msg += f"(HTTP status code: { status } )"
732- raise EasyBuildError ( error_msg )
740+ if error_msg :
741+ error_msg = f"Failed to download diff for { github_account } / { github_repo } commit { commit } ! ( { error_msg } "
742+ raise EasyBuildError ( error_msg , exit_code = EasyBuildExit . FAIL_GITHUB )
743+
744+ files = det_patched_files ( txt = diff_txt , omit_ab_prefix = True , github = True , filter_deleted = True )
745+ _log . debug ( "List of patched files for commit %s: %s" , commit , files )
733746
734747 # download tarball for specific commit
735748 repo_commit = download_repo (repo = github_repo , commit = commit , account = github_account )
0 commit comments