Add salt.utils.files.process_read_exception()

This is a common function to raise exceptions encountered trying to read
from a file.
This commit is contained in:
Erik Johnson 2016-02-04 04:48:13 -06:00
parent 276cf626b0
commit 1ae7c53e17

View File

@ -112,3 +112,21 @@ def rename(src, dst):
)
)
os.rename(src, dst)
def process_read_exception(exc, path):
'''
Common code for raising exceptions when reading a file fails
'''
if exc.errno == errno.ENOENT:
raise CommandExecutionError('{0} does not exist'.format(path))
elif exc.errno == errno.EACCES:
raise CommandExecutionError(
'Permission denied reading from {0}'.format(path)
)
else:
raise CommandExecutionError(
'Error {0} encountered reading from {1}: {2}'.format(
exc.errno, path, exc.strerror
)
)