Do not use str() on exceptions (#46950)

This commit is contained in:
Martin Krizek 2018-11-09 07:59:30 +01:00 committed by GitHub
parent 2436aa1a4e
commit a80c25cbd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 76 additions and 66 deletions

View file

@ -268,7 +268,7 @@ from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule, get_module_path
from ansible.module_utils.six import b, string_types
from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_native, to_text
def relocate_repo(module, result, repo_dir, old_repo_dir, worktree_dir):
@ -286,7 +286,7 @@ def relocate_repo(module, result, repo_dir, old_repo_dir, worktree_dir):
# if we already moved the .git dir, roll it back
if os.path.exists(repo_dir):
shutil.move(repo_dir, old_repo_dir)
module.fail_json(msg='Unable to move git dir. %s' % str(err))
module.fail_json(msg=u'Unable to move git dir. %s' % to_text(err))
def head_splitter(headfile, remote, module=None, fail_on_error=False):
@ -690,7 +690,7 @@ def get_head_branch(git_path, module, dest, remote, bare=False):
module.fail_json(
msg='Current repo does not have a valid reference to a '
'separate Git dir or it refers to the invalid path',
details=str(err),
details=to_text(err),
)
# Read .git/HEAD for the name of the branch.
# If we're in a detached HEAD state, look up the branch associated with
@ -992,8 +992,8 @@ def create_archive(git_path, module, dest, archive, version, repo, result):
except OSError as e:
module.fail_json(msg="Failed to move %s to %s" %
(new_archive, archive),
details="Error occured while moving : %s"
% to_native(e))
details=u"Error occured while moving : %s"
% to_text(e))
else:
# Perform archive from local directory
git_archive(git_path, module, dest, archive, archive_fmt, version)
@ -1100,7 +1100,7 @@ def main():
module.fail_json(
msg='Current repo does not have a valid reference to a '
'separate Git dir or it refers to the invalid path',
details=str(err),
details=to_text(err),
)
gitconfig = os.path.join(repo_path, 'config')